我想從ajax中獲取選項的值。 HTML代碼是:硒使用靜態ID獲取ajax的值
<select id="j_id0:searchlayout:mainform:countryVal" name="j_id0:searchlayout:mainform:countryVal" size="1" onchange="A4J.AJAX.Submit('j_id0:searchlayout:mainform',event,{'similarityGroupingId':'j_id0:searchlayout:mainform:j_id17','parameters':{'j_id0:searchlayout:mainform:j_id17':'j_id0:searchlayout:mainform:j_id17'} ,'status':'j_id0:searchlayout:mainform:statusProcess'})" style="height:2.4em;width:65%;">
<option value="" selected="selected">Select Country</option>
正如你所看到的,因爲id的HMTL代碼中,使用webdriverWait(下)沒有幫助。
dropdownCountry = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
((By.ID, "j_id0:searchlayout:mainform:countryVal")))
我試圖
dropdownCountry = wait.until(EC.element_to_be_clickable((By.XPATH, "//select[@id='j_id0:searchlayout:mainform:countryVal']/option")))
,但它不會產生一個列表。
一個選項是使用time.sleep(),給驅動程序足夠的時間來加載國家列表。但我知道這不是一個好習慣。
任何建議表示讚賞。 感謝
我認爲這不是一個壞習慣 –
或使用 - > http://selenium-python.readthedocs.io/waits.html#implicit-wa它的 –