Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查找从使用Seleium IDE webdriver和python的文本开始_Python_Selenium Webdriver_Selenium Ide - Fatal编程技术网

查找从使用Seleium IDE webdriver和python的文本开始

查找从使用Seleium IDE webdriver和python的文本开始,python,selenium-webdriver,selenium-ide,Python,Selenium Webdriver,Selenium Ide,下面的代码是从SeleniumIDE导出到python/webdriver生成的。我遇到的问题是括号中的数字是动态的,我不知道会是什么。但是我存储的第一部分“公司:站点” Select(驱动程序。按id(“id\U customersite”)查找元素)。按可视文本(“公司:站点(15)”选择元素。 我想做的是: `Select(driver.find_element_by_id("id_customersite")).select_by_starswith("Company: Site")`

下面的代码是从SeleniumIDE导出到python/webdriver生成的。我遇到的问题是括号中的数字是动态的,我不知道会是什么。但是我存储的第一部分“公司:站点”

Select(驱动程序。按id(“id\U customersite”)查找元素)。按可视文本(“公司:站点(15)”选择元素。

我想做的是:

`Select(driver.find_element_by_id("id_customersite")).select_by_starswith("Company: Site")`

但是,我似乎无法在python中使用正确的语法进行此操作。

在这种情况下,您必须使用“by xpath”定位器和函数“手动”选择选项:

select = driver.find_element_by_id("id_customersite")
option = select.find_element_by_xpath("//option[starts-with(., 'Company: Site')]")
option.click()

在这种情况下,您必须使用“by xpath”定位器和函数“手动”选择选项:

select = driver.find_element_by_id("id_customersite")
option = select.find_element_by_xpath("//option[starts-with(., 'Company: Site')]")
option.click()