how to select a value from dynamic searchbox in selenium webdriver java?

心已入冬 提交于 2021-01-29 10:18:56

问题


enter image description here

I have to select a name from this searchbox based on my input value. How I can achieve this.


回答1:


Option 1:

If html tag for Account name is <select>...</select>, you can use org.openqa.selenium.support.ui.Select

See https://www.guru99.com/select-option-dropdown-selenium-webdriver.html

Option 2:

Use relationship parrent-child of elements. See Selenium Java : Dropdown items are updated dynamically and https://www.tutorialspoint.com/locating-child-nodes-of-webelements-in-selenium




回答2:


#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()


来源:https://stackoverflow.com/questions/65714687/how-to-select-a-value-from-dynamic-searchbox-in-selenium-webdriver-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!