c# - Selenium WebDriver(IE 驱动程序)无法找到包含 ID 子字符串的元素

标签 c# internet-explorer selenium selenium-webdriver internet-explorer-9

_driver.FindElement(By.CssSelector("[id$='_NewSiteMaintenanceButton']"));

上面的行适用于 Chrome 和 FireFox,但是当我尝试在 IE 中执行它时,我得到:

Test Outcome: Failed Result

Message: OpenQA.Selenium.NoSuchElementException : Unable to find element with css selector == [id$='_NewSiteSearch_listbox'] Result StackTrace:

at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)

at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)

at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)

at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)

at OpenQA.Selenium.By.<>c__DisplayClass1e.b__1c(ISearchContext context)

at OpenQA.Selenium.By.FindElement(ISearchContext context)

at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)

造成这种情况的原因是什么?我该如何解决?

编辑: 显式调用它:

_driver.FindElement(By.CssSelector("[id='#3_NewSiteMaintenanceButton']"));

也失败了,而在 Chrome 和 FireFox 中则有效

最佳答案

或者,查找元素 By.xpath():

_driver.FindElement(By.xpath("//*[ends-with(@id, '_NewSiteMaintenanceButton']"));

关于c# - Selenium WebDriver(IE 驱动程序)无法找到包含 ID 子字符串的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28195776/

相关文章:

c# - 如何在 C++/cli 中声明委托(delegate)并在 C# 中使用它

javascript - 浏览器语言。奇怪的行为 - Javascript

javascript - 通过 Jquery 在 IE 中设置背景颜色

java - JUnit 注释未运行

c# - 我应该将图像作为二进制信息还是作为 FS 上的路径保存到数据库本身?

c# - 如何获得枚举标志值的最短表示?

html - Chrome - Colspan 无法按预期工作

java - 为什么 webdriver 对于不同的 id 和 xPath 索引返回相同的元素?

Selenium 从 xpath 获取动态 id

c# - 将 JSON 表示为 C# 类