I have an input element that opens a new popup window when clicked (where the user can select a value for the field).
Markup:
<html>
<input type="text" id="myPopup" readonly="readonly" name="myPopup">
</html>
c#:
var driver = new PhantomJSDriver(#"C:\PhantomJS");
driver.Navigate().GoToUrl(#"http://username:password#localhost/myUrl.aspx");
var popupField = driver.FindElementById("myPopup");
popupField.Click();
(I'm passing credentials in the URL for Windows Authentication)
I get a WebDriverException:
"The HTTP request to the remote WebDriver server for URL ...element/:wdc:1389663237442/click timed out after 60 seconds."
All other interactions I tried work except this particular element. Also tried with IE/Chrome drivers and it worked.
Any ideas?
PhantomJS 1.9.2,
C# / GhostDriver,
Selenium Webdriver 2.39,
Windows 7 x64.
Let me know if there's any other info I can provide.
I had a similar issue. Tests worked on FF but timed out on PhantomJs, as you describe. The pages I was testing used a lot of social media plugins which I think were using XHR. Removing most of the security restrictions on PhantomJs fixed it for me (see below).
service.IgnoreSslErrors = true;
service.WebSecurity = false;
service.LocalToRemoteUrlAccess = true;
service.DiskCache = true; // Dunno what this does but I thought it might help.
PhantomJSDriver driver = new PhantomJSDriver(service);
Related
Selenium driver.get (url) wait till full page load. But a scraping page try to load some dead JS script. So my Python script wait for it and doesn't works few minutes. This problem can be on every pages of a site.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://www.cortinadecor.com/productos/17/estores-enrollables-screen/estores-screen-corti-3000')
# It try load: https://www.cetelem.es/eCommerceCalculadora/resources/js/eCalculadoraCetelemCombo.js
driver.find_element_by_name('ANCHO').send_keys("100")
How to limit the time wait, block AJAX load of a file, or is other way?
Also I test my script in webdriver.Chrome(), but will use PhantomJS(), or probably Firefox(). So, if some method uses a change in browser settings, then it must be universal.
When Selenium loads a page/url by default it follows a default configuration with pageLoadStrategy set to normal. To make Selenium not to wait for full page load we can configure the pageLoadStrategy. pageLoadStrategy supports 3 different values as follows:
normal (full page load)
eager (interactive)
none
Here is the code block to configure the pageLoadStrategy :
Firefox :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities().FIREFOX
caps["pageLoadStrategy"] = "normal" # complete
#caps["pageLoadStrategy"] = "eager" # interactive
#caps["pageLoadStrategy"] = "none"
driver = webdriver.Firefox(desired_capabilities=caps, executable_path=r'C:\path\to\geckodriver.exe')
driver.get("http://google.com")
Chrome :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities().CHROME
caps["pageLoadStrategy"] = "normal" # complete
#caps["pageLoadStrategy"] = "eager" # interactive
#caps["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(desired_capabilities=caps, executable_path=r'C:\path\to\chromedriver.exe')
driver.get("http://google.com")
Note : pageLoadStrategy values normal, eager and none is a requirement as per WebDriver W3C Editor's Draft but pageLoadStrategy value as eager is still a WIP (Work In Progress) within ChromeDriver implementation. You can find a detailed discussion in “Eager” Page Load Strategy workaround for Chromedriver Selenium in Python
#undetected Selenium answer works well but for the chrome, part its not working use the below answer for chrome
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capa = DesiredCapabilities.CHROME
capa["pageLoadStrategy"] = "none"
browser= webdriver.Chrome(desired_capabilities=capa,executable_path='PATH',options=options)
The same method used in the test automation project I wrote in c # does not work in internet explorer 11 even though the movement method I use is chrome, firefox and edge. It does not give any errors, but the next action is fail
log.Debug("fare " + by + " üzeriine dogru haraket ediyor, webelement label ");
IWebElement element = GetElement(by);
Actions Actions = new Actions(Driver);
WaitElementToClickable(Driver, by, 5);
Actions.MoveToElement(element);
Actions.Perform();
WaitElementToClickable(Driver, by, 5);
I spent a long time trying to get actions to work across all browsers, and for IE I found the following helped.
Selenium webdriver v2.29.0 (https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG) added:
IEDriver supports "requireWindowFocus" desired capability. When
using this and native events, the IE driver will demand focus and
user interactions will use SendInput() for simulating user
interactions. Note that this will mean you MUST NOT use the
machine running IE for anything else as the tests are running.
When I set the IEDriver I use:
InternetExplorerOptions options = new InternetExplorerOptions();
options.requireWindowFocus();
webDriver = new InternetExplorerDriver(options);
And all my move to and click events work fine. I'm using IE11.125-11.309 and Selenium (java bindings) 3.7.1.
How can I reset Chrome's zoom level to Default(100%) using Selenium WebDriver? It's really easy to do using keyboard keys "Ctrl + 0".
However, when I try to emulate this using WebDriver, I can't get anything to work. Here is what I tried without success:
[TestMethod]
public void ZoomToDefaultLevelWithChrome()
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.ultimateqa.com");
var actions = new Actions(driver);
var browser = (IJavaScriptExecutor)driver;
var html = driver.FindElement(By.TagName("html"));
//None of these work
actions.SendKeys(Keys.Control).SendKeys(Keys.Add).Perform();
actions.KeyDown(Keys.Control).SendKeys(Keys.NumberPad0).Perform();
//actions.KeyDown(Keys.Control).SendKeys(Keys.NumberPad0).Perform();
//actions.KeyDown(Keys.Control).SendKeys(html, "0").Perform();
actions.KeyUp(Keys.Control);
actions.KeyDown(Keys.Control).Perform();
actions.SendKeys(html, "0").Perform();
actions.SendKeys(html, Keys.NumberPad0).Perform();
actions.SendKeys(Keys.NumberPad0).Perform();
browser.ExecuteScript("document.body.style.zoom = '1.0'");
browser.ExecuteScript("document.body.style.transform='scale(1.0)';");
browser.ExecuteScript("document.body.style.zoom='100%';");
}
The first 2 solutions from here don't work in C#: Selenium webdriver zoom in/out page content
Also, this doesn't work in Chrome even though it might in other browsers: selenium vba code to zoom out webpage to 60%
Can you try the below. This should work.
((IJavaScriptExecutor)driver).executeScript("document.body.style.zoom='100%';");
I have also encountered this problem, a work around I found was good was setting the the resolution capability
capability.SetCapability("resolution", 1920x1080);
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
//Dev environment
driver.Url = /*URL*/;
var trialGroupName = driver.FindElement(By.Name("TrialGroupName"));
trialGroupName.SendKeys(/*trial group name */);
var userName = driver.FindElement(By.Name("UserName"));
userName.SendKeys(/*username*/);
var password = driver.FindElement(By.Name("UserPassword"));
password.SendKeys(/*password*/);
var loginButton = driver.FindElement(By.Id("Ok"));
loginButton.Click();
//Find and click on Browse tab
var browseTab = driver.FindElement(By.Id("17"));
browseTab.Click();
}
}
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"id","selector":"17"}
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)'
Here's the inspect information:
<td>
<a id="17" class="defaultMenu initMenu" href="javascript:onMenuHref(17)" notran="">Browse</a>
</td>
I've also tried running it with the XPath (both the short version from Chrome and the long version from FireBug) and I receive the same error. I've tried adding in an implicit wait and a Thread.Sleep() but still received the same error. Also tried starting on a different field and tabbing to it and then it gave me the same exception but on the new field. I also tried playing around with cssSelector this morning and couldn't get that to work either. I did try to do an explicit wait but I'll be honest, I'm still trying to digest and understand it as waits are a new concept and I don't fully understand it, so I don't think I'm doing it right.
I'm a beginner, and I'm currently just trying to write the script to get it to the actual page that needs testing. I've been teaching myself some coding and selenium as I'm the only QA person at my company right now and I really think we could benefit from automation. This portion of the page isn't actually programmed by us it's done by a third party who hosts the system we use so I'm limited to what I see in the inspect.
(I commented out the user login information and URL because it is for internal use only and the page can't be reached outside of our systems anyways. Also I'm pretty sure I'm not allowed to do so by my employer).
Any help on this would be greatly appreciated, or any additional resources I can use. I've been using google mostly so there may be other pages you are aware of that could help me that I haven't found yet.
The login button takes you to a new page, which you need to wait for it to load. Try using an explicit wait to wait for the tab to be clickable. The timeout is 10 seconds in the following example, so modify that as needed.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement browseTab = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("17")));
Trying to test a simple page using Selenium running from Visual studio 2013 in C#. Internet explorer 11 starts and goes to the correct page, but cannot find an element from it's class (the very next thing it does). You can use developer tools to see this class as clear as day and this is the only place it's used. Note this works fine in Chrome and Firefox, using the same test .
The HTML is;
<input class="btn btn-default" type="submit" value="Log in">
and the code I'm using to find it is;
IWebElement logIn = new WebDriverWait(Driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists(By.ClassName("btn")));
I've tried turning "Protected mode" to off for all four internet zones, but still no joy.
This can be an issue with the Native vs Synthetic event of operating system. Read this. Disabling native events of IEDriver should help you in such case.
I do the following with same environment you have
var options = new InternetExplorerOptions { EnableNativeEvents = false };
Driver = new InternetExplorerDriver(options);
I think it might be fixed if you use CssSelector or Xpath instead of ClassName
IWebElement logIn = new WebDriverWait(Driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists(By.CssSelector("input[class='btn btn-default']"));