I've written the sample like in documentation:
var driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("Cheese");
Console.WriteLine("Title is: " + driver.Title);
driver.Quit();
But I always get Unable to find element with name == q
error.
The IE9 is opened, google page is 开发者_JS百科loaded, I can read driver.Title
, but cannot find any element by name, by selector, or by id.
Any thoughts?
UPD:
Terrible thing is that this code works on my desktop (Windows 7, VS 2010 Express) and doesn't work in virtual machine (VmWare player, Windows 2008 R2 SP 1 trial, VS 2010 Ultimate trial) :-(
And it doesn't work there for custom dummy <input name="q" />
page
UPD 2:
The code works for Firefox driver, but doesn't for IE.
SOLUTION:
Seems like the site should be in "Trusted" for Windows server installation. I'm not sure why, but adding google.com
to trusted solved an issue
The site should be in "Trusted" for Windows server installation. I'm not sure why, but adding google.com to trusted solved an issue
The problem might be cos of the fact that the google search box now loads after page load and thus it might be the case that the control does not exist when selenium was searching for it.
use a custom search method in this case and in the method you should have the following code:
for (var retry = 0; retry < 10; retry++)
{
try
{
if (driver.Until(driver => driver.FindElement(searchBy).Displayed))
return;
}
catch (StaleElementReferenceException)
{
}
}
Hope this helps.
Update: Also since the author has mentioned abt the Security issue of IE I would like to pointout that I think you dont have to set it to trusted all you sites need to share the same security level.
Zerkms, trying putting some wait time after your .navigate statement also use xpath to locate the element if by name doesn't work.
精彩评论