Tuesday, 7 March 2017

[Selenium] How to check if a checkbox is selected in Selenium WebDriver

我試過is_Enable() 但是都得到是true,所以現在用get_attribute來確認


I have tried is_Enable method but I always get true.
I decide to use "get_attribute" but its return is true/None. not false. Be carefull

[updated] I found answer. I should use is_selected() rather than is_enabled()


is_enabled()
Returns whether the element is enabled.
is_selected()
Returns whether the element is selected.


from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Firefox()
driver.get("your.site.with.dragndrop.functionality.com")
selement = driver.find_element_by_id("widgetID")
print(element.get_attribute("checked"))  //true
element.click()
print(element.get_attribute("checked"))  //None
element.click()
print(element.get_attribute("checked"))  //true

No comments:

Post a Comment

how-to-recursively-create-subfolder-in-each-folder-of-a-directory-in-cmd

test.cmd: @echo off setlocal for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do ( rem enter the directory pushd %%a echo...