python自動化:下拉框定位方法之select標簽 style="display: none;"
報錯
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated
界面源碼:(禪道為例)
排查:
1)因為是隱藏的,需要操作其可見才可定位
2)若還是無法定位,請查看前后是否有sleep等待;xpath定位效率會低點。
'''
select標簽定位
使用index
若是操作隱藏的元素的話:;【若不是隱藏的的話不需要js】
js = 'document.querySelectorAll("select")[0].style.display="block";'
driver.execute_script(js)
------
document.querySelectorAll("select") 選擇所有的select。
[0] 指定這一組標簽里的第幾個。
style.display="block"; 修改樣式的display="block" ,表示可見。
執行完這句js代碼后,就可以正常操作下拉框了。
'''
#index定位;導入:from selenium.webdriver.support.select import Select
js = 'document.querySelectorAll("select")[2].style.display="block";'#[2]:從零開始查第幾個就寫幾
driver.execute_script(js)
project = driver.find_element_by_xpath("http://*[@id='project']")
Select(project).select_by_index(1) #從零查第幾個option
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。