How to get xpath

50 Views Asked by At
Don’t have account? Sign up

I need to click on sign up text with xpath but unable to get the xpath for the web element get no Unable to locate element message

Tried with below xpath:

//button[@class='upload_btn' and contains(text(), 'Sign up')]

And

//button[normalize-space()='Sign up']
2

There are 2 best solutions below

0
Morddekaiser On

Hey I can help with this. if you are able to provide the URL of the page with element you want to get i can give you a more detailed answer. something like this should work.

buttons = driver.find_element(By.TAG_NAME, 'button')
for button in buttons:
    if button.text == "Sign up"
        button.click()

this is a basic for loop which will use selenium to search for all the buttons on the page and store them. after that is looks at each buttons text element to decide which one says sign up and clicks on it.

I would recommend using Tags and classes when looking at elements as xpath can harder to work with. I hope this helps if you need anything else please let me know happy codeing! :)

0
KunduK On

you need to wait for the element to be visible and then able to click on the element. Use some explicit condition,when interacting the element.

However your first xpath was a typo. There was a trailing spaces in the class name, Please use the below xpath. Should work with explicit wait.

//button[@class='upload_btn ' and text()='Sign up']

OR

//button[text()='Sign up']