简体   繁体   English

Python Selenium选择元素列表

[英]Python Selenium choose element list

WebDriverWait(self.browser, 5).until(
            expected_conditions.presence_of_element_located((By.ID, "name")))
query = driver.find_element_by_id('name') 
query.send_keys('python')
options_list = driver.find_element_by_xpath('path with element list') 
target_option = WebDriverWait(options_list, 5).until(expected_conditions.presense_of_element_located((By.XPATH, "[text()[contains(.,'python')]]")))
driver.send_keys(Keys.ENTER)

This is my code. 这是我的代码。 I should open list and choose 'python', this code is ok when i use time.sleep but in my exercises i can't use time.sleep My list slow a load and First I write a 'python' and and then the list is loaded. 我应该打开列表并选择“ python”,当我使用time.sleep时此代码可以,但是在我的练习中我不能使用time.sleep我的列表减慢了加载速度,首先我编写了“ python”,然后再创建列表已加载。

Your code block without the time.sleep(7) looks perfect. 您的代码块没有time.sleep(7)看起来很完美。 The changes you need to make are as follows. 您需要进行的更改如下。 In the first wait as you are sending text you need to change the expected_conditions clause from presence_of_element_located to element_to_be_clickable and in the second wait as you are waiting for the text python to be visible you need to change the expected_conditions clause from presence_of_element_located to visibility_of_element_located as follows : 在第一次的等待 ,你要发送的文字,您需要将改变expected_conditions条款从presence_of_element_locatedelement_to_be_clickable和第二等待你正在等待文本蟒蛇是可见的,你需要改变expected_conditions条款从presence_of_element_locatedvisibility_of_element_located如下:

WebDriverWait(self.browser, 5).until(expected_conditions.element_to_be_clickable((By.ID, "name"))).send_keys('python')
options_list = driver.find_element_by_xpath('path with element list') 
target_option = WebDriverWait(options_list, 5).until(expected_conditions.visibility_of_element_located((By.XPATH, "//*[contains(.,'python')]")))
driver.send_keys(Keys.ENTER)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM