0

I am trying to click a vote button on a webpage. I can navigate the page with my python code and click on a radio button. The vote button is not declared as a "button" or "input" element in the HTML code. I am really unsure of how to have Selenium navigate to it and click on it. The button itself does not link to a web address. I have tried tabbing to it and then hitting enter but it tabs over the button itself. I can provide further HTML and any other supplementary information. A picture of the HTML is below!

HTML Code of the button

6
  • The "a" in the HTML as far as I have read about is an "anchor element". I do not know HTML so I am having a hard time finding a work around for the way this button operates. Commented Feb 28, 2020 at 2:25
  • Maybe try finding the element by xpath, and see whether that works? Commented Feb 28, 2020 at 2:32
  • I have tried that route but even by using the xpath I can’t click on the element. It’s as if it isn’t recognized as a clickable item. Commented Feb 28, 2020 at 2:34
  • Could you add a link to the webpage if possible? Commented Feb 28, 2020 at 2:35
  • threerivers.okvype.com/2020/02/24/… Commented Feb 28, 2020 at 2:45

2 Answers 2

2

Try this:

from selenium import webdriver

driver_options = webdriver.ChromeOptions()
chromedriver = "path/to/chromedriver"

driver = webdriver.Chrome(chromedriver, options = driver_options)
driver.get("https://threerivers.okvype.com/2020/02/24/vote-now-okmulgee-area-preseason-baseball-poll-presented-by-muscogee-creek-nation-poll-ends-3-2/")
buttonpath = '//*[@id="pd-vote-button10509753"]'
dotpath = '//*[@id="PDI_answer48619888"]'
dot = driver.find_element_by_xpath(dotpath)
vote = driver.find_element_by_xpath(buttonpath)
dot.click()
vote.click()

It worked for me, by selecting the right elements to click. Sometimes theres a wrapping element around the button that has to receive the click instead of the target element, in order to trigger a response.

Sign up to request clarification or add additional context in comments.

Comments

0

Can you find the element using the class selectors?

I would get the SelenideElement by class and then calling the click method: $('.pds-vote-button')

1 Comment

I have tried that method using the class selectors. It didn't work. My implementation may have been incorrect.

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.