I am very new to selenium webdriver and I'm using python. I want to go to a webpage that contains(textbox, dropdowns, radio buttons, etc) and I want to tab/move from element to element w/oa "driver.find" syntax because that would defeat the purpose of automating, for some of these pages have a lot of fields. Is there a way to tab from one element to another, without getting the element's id?
Essentially, I would tab from field to field and create an if statement: If this is 'input' then do this, else if 'select' do this, etc.
Any help would be greatly appreciated? I hope I was clear? Thanks in advance.
Yeah you can do this! I will use an example for something with checkboxes:
checkboxes = driver.find_elements_by_xpath('//input[@type="checkbox"]')
for allChecks in checkboxes:
try:
allChecks.click()
except:
print("Checkbox not working")
So this finds every element that is a checkbox and checks it. with allChecks.click()
. Notice a couple of things though as when I was learning they were really subtle and I missed.
When finding one element on a page you want to use find_element_by_xpath
to find multiple elements on a page use find_elements_by_xpath
notice that elements is plural in the second one.
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.