【发布时间】:2021-01-14 07:07:07
【问题描述】:
我必须根据我的输入值从此搜索框中选择一个名称。我怎样才能做到这一点。
【问题讨论】:
-
发布它的 html 代码和您的尝试。右键单击 -> 检查 -> 复制。
-
-
你也可以对第一个元素做同样的事情吗?又名加里冲。
标签: selenium selenium-webdriver
我必须根据我的输入值从此搜索框中选择一个名称。我怎样才能做到这一点。
【问题讨论】:
标签: selenium selenium-webdriver
#send something to the input
input=driver.find_element_by_xpath("//input[@role='combobox']") #xpath to input box
input.send_keys("something")
#find the drop down element and scroll to that element
options = driver.find_element_by_xpath("xpathtotheoptiondropdown")
driver.execute_script("arguments[0].scrollIntoView();", option)
#click that element
option.click()
【讨论】:
选项 1:
如果账户名的html标签是<select>...</select>,你可以使用org.openqa.selenium.support.ui.Select
见https://www.guru99.com/select-option-dropdown-selenium-webdriver.html
选项 2:
使用元素的父子关系。
见Selenium Java : Dropdown items are updated dynamically
和https://www.tutorialspoint.com/locating-child-nodes-of-webelements-in-selenium
【讨论】: