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

The line above works with Chrome AND FireFox, but when I try to execute it in IE I get:

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)

What causes this, and how should I resolve it?

EDIT: Explicitly calling it:

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

Fails too, whereas in Chrome AND FireFox that works

1
$ part of attribute? - Saifur
@Saifur $='_NewSiteMaintenanceButton'" is supposed to get and ID that ends with _NewSiteMaintenanceButton, so if the actual ID is 111_NewSiteMaintenanceButton, it should find it. - James Madison
@Arran IE9, I cannot change the version, as that is required for our testing - James Madison
@JamesMadison, alright, so take Selenium out of the equation. Open IE's developer tools, and go it's console, run the same query there: document.querySelector('[id$='_NewSiteMaintenanceButton']')...what do you get? - Arran
@Arran $("[id$='_NewSiteMaintenanceButton']") returns length 1 - James Madison

1 Answers

2
votes

Alternatively, find the element By.xpath():

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