Skndr
Skndr

Reputation: 43

unique xpath for element span inside div inside button selenium python

Xpath

I'm looking for Unique Xpath for this element (Select) in google language settings https://myaccount.google.com/language?hl=en already have this xpath but I need something more accurate and unique

    WebDriverWait(driver, 30).until(
        EC.element_to_be_clickable((By.XPATH, 
            "//*[@id='yDmH0d']/div[11]/div/div[2]/div[3]/div[2]/button"))).click()

Upvotes: 2

Views: 556

Answers (2)

NameVergessen
NameVergessen

Reputation: 644

I would try to copy the X-Path from the Browser as discribed here: Mozilla Help

My result would be: //*[@id="lang-selector"]

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

If you pay attention to the HTMLDOM :

You can construct a xpath based on attribute name only. You do not need their values nor their text.

//div[@data-is-touch-wrapper]/button[@data-id and @aria-label]

represent two matching nodes.

(//div[@data-is-touch-wrapper]/button[@data-id and @aria-label])[2]

should get the job done.

Upvotes: 2

Related Questions