http://xkz.cbirc.gov.cn/jr/ 這個網站有幾率彈出對話框。我的任務是檢測對話框的彈出,然后做出處理。我用下面的代碼
driver.get("http://xkz.cbirc.gov.cn/jr/")
wait = WebDriverWait(driver, 10)
table_yanZhengMa = wait.until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[5]/table"))
)
print(table_yanZhengMa)
#visibilityMy = driver.find_element_by_xpath("/html/body/div[5]/table").get_attribute('id')
visibilityMy = driver.find_element_by_id("show_msg").get_attribute('style')
print(visibilityMy)
if(visibilityMy.find("visibility: visible")>=0):
print("input verification code")
else:
tmpPrice = wait.until(
EC.presence_of_all_elements_located(
(
By.XPATH,
"/html/body/div[3]/div/div[2]/div/div[1]/div/div[1]/div[2]/div/div[1]/table/tbody/tr/td[5]/div/a"
)
)
)
# print(len(tmpPrice))
# print(type(tmpPrice[0].text))
print(tmpPrice[0].text)
print(driver.find_element_by_id("queryResult").text)檢測前臺html是
<div id="show_msg" style="z-index: 20001; width: 450px; display: block; visibility: visible;">
但我的print(visibilityMy)結果是“z-index: 20001; width: 450px;”,不知道為何有時候少了,能幫忙看看嗎?是有js嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/168290.html
