Selenium单击python中的内容或按钮

2024-09-27 00:23:27 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个网页的摘录,我想在其中单击“不”按钮:

<div _ngcontent-nfa-c115="" class="col-12"><div _ngcontent-nfa-c115="" class="ets-radio-wrapper cv-radio-wrapper"><label
_ngcontent-nfa-c115="" class="ets-radio-control"><input _ngcontent-nfa-c115="" type="radio" name="vaccination-approval-checked" value="1" autocomplete="off" class="form-check-input ng-untouched ng-pristine ng-valid"><span
_ngcontent-nfa-c115=""> Ja <br _ngcontent-nfa-c115=""><small _ngcontent-nfa-c115="">(Vermittlungscodes bereits vorhanden)</small></span></label><label _ngcontent-nfa-c115="" class="ets-radio-control"><input _ngcontent-nfa-c115="" type="radio" name="vaccination-approval-checked" value="0" autocomplete="off" class="form-check-input ng-untouched ng-valid ng-dirty"><span
_ngcontent-nfa-c115="">Nein<br _ngcontent-nfa-c115=""><small _ngcontent-nfa-c115="">(Anspruch prüfen)</small></span></label></div></div>

问题是Selenium找不到按钮。以下是我尝试作为评论的一些示例:

# Selenium project
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
PATH = "c:\WebDriver\chromedriver.exe" 
driver = webdriver.Chrome(PATH)
driver.get("https://lalalalal.com")
time.sleep(3)
# boton = driver.find_element_by_class_name("ng-valid").click() -> No result
# boton = driver.find_element_by_css_selector(".ng-valid").click() -> No result
# boton = driver.find_element_by_xpath("//*[@class='form-check-input ng-untouched ng-pristine ng-valid']").click() -> No result
# boton = driver.find_element_by_css_selector("a[ng-switch-when='next']").click() -> No result
time.sleep(3)
driver.quit()

问题是如何使用“查找”方法来处理单击

有什么想法吗


Tags: importdivinputbydrivernglabelclass
1条回答
网友
1楼 · 发布于 2024-09-27 00:23:27

该单选按钮具有名称属性[已检查疫苗接种批准](请参阅HTML):

因此,请尝试使用以下名称:

boton = driver.find_element_by_name("vaccination-approval-checked")
boton.click()

相关问题 更多 >

    热门问题