1

This is the button I'm trying to click:

<button class="stkv-c-button stkv-us-button-color--background 
    stkv-u-background-color-transition-150 
    stkv-us-button-color--border stkv-us-button-color 
    stkv-us-button-color--fill stkv-c-button 
    stkv-c-button--raised stkv-c-button--big">

    <span class="stkv-c-button__label stkv-c-button__label--big">Vote Now</span>
</button>

This is the xpath (pulled from Firefox):

[@id='root']/html/body/div/div/div[3]/div/div/footer/div/button"

I've tried a wide variety of ways to click on the button, all to no avail.

self.driver.find_element_by_xpath("//*[@id='root']/html/body/div/div/div[3]/div/div/footer/div/button").click()
self.driver.findElement(By.id("Vote Now")).click()
self.driver.find_element_by_name("Vote").send_keys(Keys.ENTER)
self.driver.find_element_by_id('stkv-c-button stkv-us-button-color--background stkv-u-background-color-transition-150 stkv-us-button-color--border stkv-us-button-color stkv-us-button-color--fill stkv-c-button stkv-c-button--raised stkv-c-button--big').click()

Any suggestions would be greatly appreciated!

I'm not having any luck with it.

1
  • What happens when you try to use that code? Does it throw an ElementNotFound exception? Commented Sep 24, 2018 at 0:05

4 Answers 4

1

You can find the button by display text on it.

locator = "//button[span[text()='Vote Now']]"
self.driver.find_element_by_xpath(locator).click()
Sign up to request clarification or add additional context in comments.

Comments

1

Your button doesn't have an id or name, so the find_element_by_name and find_element_by_id methods will not work. find_element_by_class_name seems like the logical choice, but unfortunately it only expects only 1 class, and since your button has multiple classes, it won't work either. I would try locating the button with its CSS selector:

self.driver.find_element_by_css_selector('button.stkv-c-button.stkv-us-button-color--background.stkv-u-background-color-transition-150.stkv-us-button-color--border.stkv-us-button-color.stkv-us-button-color--fill.stkv-c-button.stkv-c-button--raised.stkv-c-button--big').click()

As long as there isn't another button on the page with the exact same CSS selector, this should give you the correct button. In general, if you want to find an element that has multiple classes, e.g. <button class="A B C">MyButton</button>, then you could do it with:

self.driver.find_element_by_css_selector('button.A.B.C')

Comments

1

Use this XPath : //button[normalize-space()='Vote Now']

Comments

1

As per the HTML you have shared to click() on the button with text as Vote Now you can use either of the following solution:

  • CSS_SELECTOR:

    driver.find_element_by_xpath("span.stkv-c-button__label.stkv-c-button__label--big").click()
    
  • XPATH:

    driver.find_element_by_css_selector("//span[@class='stkv-c-button__label stkv-c-button__label--big' and contains(.,'Vote Now')]").click()
    

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.