0

I am currently writing a program in Python using SeleniumBase, however, I want to click a button via the text inside it and it is not working. This is an example code block:

from seleniumbase import BaseCase

BaseCase.main(__name__, __file__)

class MultipleDriversTest(BaseCase):
    def test_multiple_drivers(self):
        
        LINK = "https://invideo.io/perf/ga-ai-video-generator-web/?utm_source=google&utm_medium=cpc&utm_campaign=Top16_Search_Brand_Exact_EN&adset_name=InVideo&keyword=invideo&network=g&device=c&utm_term=invideo&utm_content=InVideo&matchtype=e&placement=g&campaign_id=18035330768&adset_id=140632017072&ad_id=616240030555&gad_source=1&gclid=Cj0KCQiAvvO7BhC-ARIsAGFyToWFf0L_8iqkB32qg9prKxVApsklZ8HA69LW2O0Z6XC1nbXXz9sCTTEaAinZEALw_wcB""https://invideo.io/perf/ga-ai-video-generator-web/?utm_source=google&utm_medium=cpc&utm_campaign=Top16_Search_Brand_Exact_EN&adset_name=InVideo&keyword=invideo&network=g&device=c&utm_term=invideo&utm_content=InVideo&matchtype=e&placement=g&campaign_id=18035330768&adset_id=140632017072&ad_id=616240030555&gad_source=1&gclid=Cj0KCQiAvvO7BhC-ARIsAGFyToWFf0L_8iqkB32qg9prKxVApsklZ8HA69LW2O0Z6XC1nbXXz9sCTTEaAinZEALw_wcB"
        self.activate_cdp_mode(LINK)
        driver = self.driver
        driver.sleep(10)
        driver.click('//button[contains(text(), "Sign up"]')

When I run this, I get the error:

Element {//button[contains(text(), "Sign up"]} was not found after 7 seconds!

I believe the XPATH to be correct, or have I done something wrong?

1
  • you could check what buttons it can find - and display text from all buttons. Maybe it get button with different text - in different language. Commented May 4 at 23:07

2 Answers 2

0

You have missed the closing parenthesis for contains function. That is why it is not finding the element. The following is working.

 driver.click('//button[contains(text(), "Sign up")]')
Sign up to request clarification or add additional context in comments.

Comments

0

Use CSS Selectors when using CDP Mode. Your selector would look like this:

'button:contains("Sign up")'

In a working script, it would look like this:

from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)

class MyTest(BaseCase):
    def test_one(self):
        self.activate_cdp_mode("https://invideo.io/")
        self.sleep(2)
        self.click('button:contains("Sign up")')
        self.sleep(4)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.