[英]how to click button in python selenium?
<div class="gift">
<button type="button" data-log-actionid-label="gift" data-log-body="{"current_product_no" : "1003072802", "group_product_no" : "", "group_product_firstview_no" : "", "product_price" : "5600", "send_impression": "Y"}" data-is-send-log="true">
togift
<span class="ic_new">new</span>
</button>
</div>
Can't use by text, because this page have lots of text togift
不能通过文字使用,因为这个页面有很多文字
togift
How can I click this button ?我怎样才能点击这个按钮?
You can try using the class name
:您可以尝试使用
class name
:
div = driver.find_element_by_class_name('gift')
btn = div.find_element_by_xpath('.//button')
btn.click()
If there are other tags with the same class name, then you can use the css selector
or the full xpath
如果还有其他标签具有相同的类名,那么您可以使用
css selector
或full xpath
应该点击带有按钮的 div 类礼物。
driver.find_element_by_xpath("div[class='gift']/button").click()
Not enough html source to let us know how to write a correct and short element's location statement.没有足够的 html 源代码让我们知道如何编写正确且简短的元素位置声明。 So just try the below
xpath expressions
:所以只需尝试以下
xpath expressions
:
"//div[@class='gift']/button[contains(text(),'togift') and ./span[contains(text(),'new')]]"
"//div[@class='gift']/button[contains(text(),'togift')]"
"//div[@class='gift']/button"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.