In python I am trying to select this element
<button stid="FLIGHTS_DETAILS_AND_FARES-index-1-LDUWT-FlightsActionButton" data-test-id="select-link" data-stid="FLIGHTS_DETAILS_AND_FARES-index-1-LDUWT-FlightsActionButton" class="uitk-card-link" type="button"><span class="is-visually-hidden">Select and show fare information for Etihad Airways flight, departing at 10:50am from Geneva, arriving at 1:05pm in Tokyo, Priced at $2,224 Roundtrip per traveler. Arrives 1 day later. 19 hours 15 minutes total travel time, One stop, Layover for 3 hours 10 minutes in Abu Dhabi.</span></button>
and to extract the text. I tried to use the following expression
element = browser.find_element(By.XPATH, "//button[@stid='FLIGHTS_DETAILS_AND_FARES-index-1-LDUWT-FlightsActionButton']")
print(element.text)
I also tried
element = browser.find_element(By.XPATH, '//button[contains(text(), "Select and show fare information")]')
print(element.text)
which results in an "Unable to locate element" error.
Also the stid element might change between calls to the webpage.
>Solution :
your locators were not correct, i ahve corrected both you have provided above
try any of these below and Extract the text for the span element
#1 Since part of ID is dynamic you can just use contains
//button[contains(@stid,'FLIGHTS_DETAILS_AND_FARES')]//span
#2 The text element Tag is actually span not button
//span[contains(text(), "Select and show fare information")]