_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/