简体   繁体   English

如何使用selenium python单击文本按钮

[英]How to click on the text button using selenium python

Hi I'm trying to click on select button using xpath and css selector but it doesn't works 嗨,我正在尝试使用xpath和css选择器单击选择按钮,但它不起作用

browser.find_elements_by_xpath('//div[@class="section-select-all"]').click()
browser.find_elements_by_css_selector('#results-container > form > ul > li:nth-child(1) > div > div > button').click()
browser.find_elements_by_xpath('//*[@id="results-container"]/form/ul/li[1]/div/div/button').click()

please let me know how it would be here is the code 请告诉我这里的代码是什么

<div class="section-actions"><button type="button" class="section-select-all">Select 50<span class="screen-reader-text"> for section Dec 11, 2015</span></button></div>

You're using elements that will not work. 你使用的elements不起作用。 Use element instead. 请改用element I am sure it will work. 我相信它会奏效。

Keep it simple.If there is a single button then try: 保持简单。如果只有一个按钮,请尝试:

Example 1 - 例1 -

browser.find_element_by_class_name("section-select-all").click()

If multiple buttons with same class name then you can use this: 如果具有相同类名的多个按钮,则可以使用此:

Example 2 - 例2 -

buttons = browser.find_elements_by_class_name("section-select-all")
for button in buttons:
    button.click()

If the buttons are in a frame, then make sure you switch to the frame before clicking on it. 如果按钮位于框架中,请确保在单击之前切换到框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM