Search code examples
pythonselenium-webdriverwebdriverwait

Issue selecting button tag with text using Selenium WebDriverWait


I can´t select a button with a specific text (hence can´t do click on it).

This is a image of the button:

enter image description here

and this is its html code:

enter image description here

When using WebDriverWait and the text 'Confirm payment', the button gets selected properly.

WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='Button_content__guezZ' and text()='Confirm payment:']")))

What I need is to select the button according to the amount, that means including the price in the text but when I do so, WebDriverWait won´t work anymore.

I tried several ways, basically using the same WebDriverWait above adding some variations in the text: 'Confirm payment: 0,01 €', '0,01 €', '0,01 €'. All of them with no luck.

When using only 'Confirm payment:' the code works, on the other hand when I include the amount, it´s not working anymore.

I'm running out of ideas. What am I doing wrong?


Solution

  • You need to filter the button text. Use Xpath text contains - first for the word payment, then for the amount you are required to pay.

    xpath_exp = '//div[@class="Button_content__guezZ"]
    [contains(text(), "payment")][contains(text(), "0,01")]'
    WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, xpath_exp)))
    

    You can concatenate attributes filtering using this method and find specific element that contains 2 or more text phrases.