点击此 page 上的“县”下拉菜单我将此 XPath 与 Selenium 结合使用:
driver.find_elements_by_xpath('//div[@class="masterCustomDropDown"]/img')[3].click()
由于有时不会出错,也不会实际执行点击操作,所以我通常会检查下拉菜单中的元素是否可见,以查看是否执行了点击功能。有更好的方法吗?
谢谢!
最佳答案
您可以尝试使用Select()
//Create a new select element
Select choose = new Select(driver.find_elements_by_xpath('//div[@class="masterCustomDropDown"]/img'))
//Select the element at the 3rd index in the Select element we have reference to
choose.selectByIndex(3)
关于Python Selenium 下拉菜单选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52600350/