简体   繁体   English

硒; 无法在Internet Explorer中按类查找元素

[英]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#. 尝试使用从C#中的Visual Studio 2013运行的Selenium测试一个简单的页面。 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). Internet Explorer 11会启动并转到正确的页面,但无法从其类中找到元素(它要做的下一件事)。 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 . 请注意,使用相同的测试在Chrome和Firefox中可以正常工作。

The HTML is; HTML是;

<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. 我尝试将所有四个Internet区域的“保护模式”都关闭,但仍然没有任何乐趣。

This can be an issue with the Native vs Synthetic event of operating system. 这可能是操作系统的本机vs合成事件的问题。 Read this . 阅读 Disabling native events of IEDriver should help you in such case. 在这种情况下,禁用IEDriver的本机事件应该可以为您提供帮助。

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']"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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