简体   繁体   中英

Selenium; Unable to find element by class in Internet Explorer

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);

我认为如果使用CssSelector或Xpath代替ClassName可能会解决

IWebElement logIn = new WebDriverWait(Driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists(By.CssSelector("input[class='btn btn-default']"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM