Home > Software engineering >  Selenium Python find elemnt with incomplete info
Selenium Python find elemnt with incomplete info

Time:05-28

This site displays a simple check box, now i want to get selenium to check the box by only proving the middle part of the value attribute i.e part2

but I get an error no such element , How do i go ahead with this?

<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()

CodePudding user response:

Try:

abutton = driver.find_element(By.XPATH, "//input[contains(@value='part2')]")
abutton.click()
  • Related