0

I need to parse prices from

enter image description here

I want to take the maximum possible period. But when I use

enter image description here

driver.find_elements(By.CLASS_NAME, 'btn-group')[-1].click()

I get 15 years.

How I can fix it?

Can I additionally upload all these elements to the list and select the last one from them?

2
  • Not smart way, but maybe by text ? "driver.find_element_by_xpath("//div[@class='btn btn-default btn-xs' and text()='30y']") " Commented Aug 25, 2022 at 12:34
  • I thought about it. It seems to me that the maximum term can be different, so I would choose the last element. Commented Aug 25, 2022 at 12:46

2 Answers 2

2

Try to click on last element using xpath expression

driver.find_elements(By.XPATH, '//*[@class="btn-group"]//a')[-1].click()
Sign up to request clarification or add additional context in comments.

Comments

1

Looks like you need to put some delay before the

driver.find_elements(By.CLASS_NAME, 'btn-group')

command.
It seems that you are grabbing the elements before all of them are loaded properly.
So, I think

time.sleep(2)
driver.find_elements(By.CLASS_NAME, 'btn-group')[-1].click()

should work better

1 Comment

I checked it. I have the same result

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.