问题
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