簡體   English   中英

硒; 無法在Internet Explorer中按類查找元素

[英]Selenium; Unable to find element by class in Internet Explorer

嘗試使用從C#中的Visual Studio 2013運行的Selenium測試一個簡單的頁面。 Internet Explorer 11會啟動並轉到正確的頁面,但無法從其類中找到元素(它要做的下一件事)。 您可以使用開發人員工具來查看此類,直到今天它仍然是唯一使用的地方。 請注意,使用相同的測試在Chrome和Firefox中可以正常工作。

HTML是;

<input class="btn btn-default" type="submit" value="Log in">

我用來找到它的代碼是

IWebElement logIn = new WebDriverWait(Driver, TimeSpan.FromSeconds(5)).Until(ExpectedConditions.ElementExists(By.ClassName("btn")));

我嘗試將所有四個Internet區域的“保護模式”都關閉,但仍然沒有任何樂趣。

這可能是操作系統的本機vs合成事件的問題。 閱讀 在這種情況下,禁用IEDriver的本機事件應該可以為您提供幫助。

我在與您相同的環境下執行以下操作

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