0

I'm trying to select a button on a site where the className is the same for multiple elements and the thing that differentiates each one is the header tag.

Right now I have this

    button = browser.find_element_by_class_name('start')
    button.click()

On the webpage there are 2 buttons which are defined as the below

<h4 class="start">1:48pm</h4>
<h4 class="start">3:54pm</h4>

I am trying to specify my script to select based on the time within the header tags of the start class.Is there a way to do that using Selenium and Python?

2

2 Answers 2

0

I am not sure what you are trying to achieve. If they have a difference xpath, you can traverse from their parent. If you want to click one or another button, you can get each button time and compare them (I have never tried this before but I think this is possible)

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

Comments

0

Use xpath and select the index of the correct element. Notice we are using find_elements_... instead of find_element_....

button = browser.find_elements_by_xpath('//h4[@class="start"]')[1].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.