使用Python中的SeleniumLibrary在react Select下拉列表中选择项

使用Python中的SeleniumLibrary在react Select下拉列表中选择项,python,selenium,automation,dropdown,react-select,Python,Selenium,Automation,Dropdown,React Select,对不起,伙计们,我以前问过同样的问题,但我不能应用到我的实际任务中。(请参阅前面的任务) 我遇到了两个麻烦: 1/基于SeleniumLibrary的项目,我不知道如何通过xpath或其他共同点调用find_元素(导入webdriver) 2/通过下面的代码,SeleniumLibrary告诉我这不是有效的XPATH表达式 driver = SeleniumLibrary driver.open_browser("abc.com") driver.find_element(&

对不起,伙计们,我以前问过同样的问题,但我不能应用到我的实际任务中。(请参阅前面的任务)

我遇到了两个麻烦: 1/基于SeleniumLibrary的项目,我不知道如何通过xpath或其他共同点调用find_元素(导入webdriver)

2/通过下面的代码,SeleniumLibrary告诉我这不是有效的XPATH表达式

driver = SeleniumLibrary
driver.open_browser("abc.com")
driver.find_element("//div[@id='react-select-2--value']").click()
driver.find_element("//[test()='Core'])  --> Error here "str... is invalid XPATH Expression"
3/在上一个问题中,我解决了这个问题(作为人们的答案)

一,

@添加跨度标记

<span class="Select-value-label resourceValue" style="margin-left: 5px;" xpath="1">Core</span>
核心
您尚未提供标签

driver.find_element("//*[test()='Core']") 
您可以指定*指示任何标记或指定哪个标记输入、div等

还可以查看元素是否在iframe中,如果它在iframe中,则必须先切换到它,然后才能与它交互

iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to_frame(iframe)
driver.find_element("//div[@id='react-select-2--value']").click()
driver.find_element("//*[test()='Core']") 
Abd如果必须与iframe之外的元素交互,则必须首先从iframe切换:

driver.switch_to_default_content()
//rest of code

它可能是:driver.find_元素(//span[text()='Core']),对吗?兄弟,非常感谢你的帮助@PDHide
iframe = driver.find_element_by_xpath("//iframe")
driver.switch_to_frame(iframe)
driver.find_element("//div[@id='react-select-2--value']").click()
driver.find_element("//*[test()='Core']") 
driver.switch_to_default_content()
//rest of code