简体   繁体   中英

Find number of check-boxes on webpage, when page source contains 'type' as a string also, using selenium python

This is my code which finds number of check-boxes on the current webpage

checkboxes=driver.find_elements(By.XPATH("html/body/div[2]/div/section[8]/div/div/div[3]/div/div[2]/table/tbody/tr[1]/td[1]/input[@type='checkbox']"))

but it gives following error:

'str' object is not callable

As HTML DOM contains string "checkbox" in it.

Thus I am unable to find a way to calculate total number of check-boxes.

You should send two arguments to find_elements , like checkboxes=driver.find_elements(By.XPATH, xpath) while there is only one argument in your code- checkboxes=driver.find_elements(By.XPATH(xpath)) . So you should use:

checkboxes=driver.find_elements(By.XPATH, "html/body/div[2]/div/section[8]/div/div/div[3]/div/div[2]/table/tbody/tr[1]/td[1]/input[@type='checkbox']")

UPDATE

Regarding OP comment: If you want to get only checkboxes visible on page, use following code:

checkboxes_list = [check for check in driver_find_elements_by_xpath('//input[@type="checkbox"]') if check.is_displayed()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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