Selenium Python 查找信息不完整的元素
Selenium Python find elemnt with incomplete info
这个网站显示了一个简单的复选框,现在我想通过只证明值属性的中间部分即 part2
让 selenium 来选中该框
但是我得到一个错误,没有这样的元素,我该如何继续呢?
<html>
<head>
<body>
<div>
<input id="dfgdfg" type="checkbox" name="dof;pg" value="part1part2part3">
</div>
</body>
</head>
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
web = 'file:///I:/A350/Untitled-2.html'
driver_path = 'C:/Users/me/.wdm/drivers/chromedriver/win32/101.0.4951.41'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options,
service=Service(ChromeDriverManager().install()))
driver.get(web)
driver.implicitly_wait(5)
abutton = driver.find_element(By.XPATH, ".//input[contains(@value,'part2')]")
abutton.click()
driver.quit()
尝试:
abutton = driver.find_element(By.XPATH, "//input[contains(@value='part2')]")
abutton.click()
这个网站显示了一个简单的复选框,现在我想通过只证明值属性的中间部分即 part2
让 selenium 来选中该框但是我得到一个错误,没有这样的元素,我该如何继续呢?
<html>
<head>
<body>
<div>
<input id="dfgdfg" type="checkbox" name="dof;pg" value="part1part2part3">
</div>
</body>
</head>
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
web = 'file:///I:/A350/Untitled-2.html'
driver_path = 'C:/Users/me/.wdm/drivers/chromedriver/win32/101.0.4951.41'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options,
service=Service(ChromeDriverManager().install()))
driver.get(web)
driver.implicitly_wait(5)
abutton = driver.find_element(By.XPATH, ".//input[contains(@value,'part2')]")
abutton.click()
driver.quit()
尝试:
abutton = driver.find_element(By.XPATH, "//input[contains(@value='part2')]")
abutton.click()