0

图1

图2

我需要找到元素“16”,我的项目使用driver = SeleniumLibrary

driver.open_browswer("..."_
driver.find_element ("//div[@id='react-select-4--value']").click()
driver.scroll_element_into_view("//span[contains(text(),'16']")
driver.find_element("//span[contains(text(),'16']").click()

我可以点击 react-dropdown 列表,但我不能scroll_element_into_view用来找到那个元素然后 click()

4

2 回答 2

1

如果有输入元素,您可以像这样直接发送'16'

driver.find_element_by_xpath('xpath_of_element').send_keys(16)

如果有 Option 元素,那么您可以使用以下方法进行选择

from selenium.webdriver.support.ui import Select

element = Select(driver.find_element_by_xpath("//div[@id='react-select-4--value']"))
element.select_by_value("16")
于 2021-01-15T07:06:14.287 回答
0
option = driver.find_element("//span[contains(text(),'16')]")
driver.execute_javascript("arguments[0].scrollIntoView();", option)

你可以试试这个,

于 2021-01-15T07:51:25.667 回答