簡體   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)

這是我的代碼。 我應該打開列表並選擇“ python”,當我使用time.sleep時此代碼可以,但是在我的練習中我不能使用time.sleep我的列表減慢了加載速度,首先我編寫了“ python”,然后再創建列表已加載。

您的代碼塊沒有time.sleep(7)看起來很完美。 您需要進行的更改如下。 在第一次的等待 ,你要發送的文字,您需要將改變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