[xpath] Click a button with XPath containing partial id and title in Selenium IDE

Using Selenium IDE, I'm trying to click a button within a table on a webpage using XPath with a partial id and a title from the element. The XPath I'm using is:

xpath=//*[contains(@id, 'ctl00_btnAircraftMapCell')]//*[contains(@title, 'Select Seat')] 

and thats the entire html code for an example of the buttons im trying to click:

<li id="ctl00_MainContent_repAircraftMap_ctl20_repAircraftMapRow??_ctl00_liAircraftMap??Cell" class=""> 
    <a id="ctl00_MainContent_repAircraftMap_ctl20_repAircraftMapRow??_ctl00_btnAircraftMa??pCell" href="javascript:void(0)" seatnumber="20A" mapbindattribute="1124" title="Select Seat 20A" onclick="SeatClick(1124);"></a> 
</li>

Am I constructing this incorrectly? It's not working!

This question is related to xpath selenium selenium-ide

The answer is


Now that you have provided your HTML sample, we're able to see that your XPath is slightly wrong. While it's valid XPath, it's logically wrong.

You've got:

//*[contains(@id, 'ctl00_btnAircraftMapCell')]//*[contains(@title, 'Select Seat')]

Which translates into:

Get me all the elements that have an ID that contains ctl00_btnAircraftMapCell. Out of these elements, get any child elements that have a title that contains Select Seat.

What you actually want is:

//a[contains(@id, 'ctl00_btnAircraftMapCell') and contains(@title, 'Select Seat')]

Which translates into:

Get me all the anchor elements that have both: an id that contains ctl00_btnAircraftMapCell and a title that contains Select Seat.


Examples related to xpath

Xpath: select div that contains class AND whose specific child element contains text XPath: difference between dot and text() How to set "value" to input web element using selenium? How to click a href link using Selenium XPath: Get parent node from child node What is the difference between absolute and relative xpaths? Which is preferred in Selenium automation testing? How to use XPath preceding-sibling correctly Selenium and xPath - locating a link by containing text How to verify an XPath expression in Chrome Developers tool or Firefox's Firebug? Concatenate multiple node values in xpath

Examples related to selenium

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser Class has been compiled by a more recent version of the Java Environment How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium? How to make Firefox headless programmatically in Selenium with Python? element not interactable exception in selenium web automation Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click How do you fix the "element not interactable" exception?

Examples related to selenium-ide

How to use XPath preceding-sibling correctly Running Selenium Webdriver with a proxy in Python Click a button with XPath containing partial id and title in Selenium IDE click command in selenium webdriver does not work Equivalent of waitForVisible/waitForElementPresent in Selenium WebDriver tests using Java? How to press/click the button using Selenium if the button does not have the Id? Does Google Chrome work with Selenium IDE (as Firefox does)? Selenium IDE - Command to wait for 5 seconds Click in OK button inside an Alert (Selenium IDE)