【问题标题】:how to select a value from dynamic searchbox in selenium webdriver java?如何从 selenium webdriver java 中的动态搜索框中选择一个值?
【发布时间】:2021-01-14 07:07:07
【问题描述】:

enter image description here

我必须根据我的输入值从此搜索框中选择一个名称。我怎样才能做到这一点。

【问题讨论】:

  • 发布它的 html 代码和您的尝试。右键单击 -> 检查 -> 复制。
  • 你也可以对第一个元素做同样的事情吗?又名加里冲。

标签: selenium selenium-webdriver


【解决方案1】:
#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()

【讨论】:

    【解决方案2】:

    选项 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-07
      • 1970-01-01
      • 2013-08-04
      • 2020-11-10
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 2014-07-05
      相关资源
      最近更新 更多