Xpath does not work with Selenium
java, selenium, selenium-webdriver, xpath
Solution
Not sure whether this is a Selenium implementation issue but this should work:
"//input[contains(@name, 'ticket')][contains(@value, '3')]"
The use of `and` is basically the same so the result should be correct here.
Problem
I'm trying to build tests for an old system. The HTML is not well formed. I need to identify and click a radio button. The html looks like this: ``` ... <td class="tablerow" colspan="3"> <INPUT type=radio name="ticket" value="22" >ramdom1 <INPUT type=radio name="ticket" value="1" >ramdom2 <INPUT type=radio name="ticket" value="3" >ramdom3 <INPUT type=radio name="ticket" value="99" >ramdom4 </td> ... ``` I was trying to select the input using xpath as follows: ``` String xpath = "//input[contains(@name, 'ticket') and contains(@value, '3')]"; WebElement rb = driver.findElement(By.xpath(xpath)); ``` But selenium doesn't found the element. If change it to ``` String xpath = "//input[contains(@name, 'ticket')]"; List<WebElement> rbs = driver.findElements(By.xpath(xpath)); ``` or ``` String xpath = "//input[contains(@value, '3')]"; List<WebElement> rbs = driver.findElements(By.xpath(xpath)); ``` It works, selenium returns a list of elements, including the one that I need. The problem occurs only when I try to use both conditions in a same xpath. Of course that I could iterate over the list and test each value, but I would like to understand if I'm doing something wrong or not. Since IE doesn´t have native xpath support, I thought this could be a selenium implementation issue. I'm using Selenium WebDriver (2.37.1) with IE Driver.