[英]How to choose last element from class using Selenium Python
I need to parse prices from我需要从
I want to take the maximum possible period.我想尽可能延长时间。 But when I use
但是当我使用
driver.find_elements(By.CLASS_NAME, 'btn-group')[-1].click(
) driver.find_elements(By.CLASS_NAME, 'btn-group')[-1].click(
)
I get 15 years.我得到15年。
How I can fix it?我该如何解决?
Can I additionally upload all these elements to the list and select the last one from them?我可以另外将所有这些元素上传到列表中,select 最后一个吗?
Try to click on last element using xpath expression尝试使用 xpath 表达式单击最后一个元素
driver.find_elements(By.XPATH, '//*[@class="btn-group"]//a')[-1].click()
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应该工作得更好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.