selenium加载用户配置:
<div>My Button</div>
按照 Text文本 来选择 对应的控件
选择的格式为:
driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]")
或者:
my_element = driver.find_element_by_xpath("//div[text()='My Button']")
参考链接:
当运行时候报错,报错信息为:
Message: element not interactable
解决方案为:
不使用自带的click() 而使用脚本
element = driver.find_element_by_xpath("(//a[contains(@href, '')])[20]")
driver.execute_script("arguments[0].click();", element)
定位元素,以下也不失为一个好方法:
save_items = []
for item in driver.find_elements_by_tag_name("input"):
# Get class
item_class = item.get_attribute("class")
# Get name:
item_name = item.get_attribute("name")
# And so on...
# Check for a match
if item_class == "W_input" and item_name == "14235541231062":
# Do your operation (or add to a list)
save_items.append(item)