Python自動化之下拉框,隱藏標籤定位 代碼&報錯解決

python自動化:下拉框定位方法之select標籤 style="display: none;"
報錯
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated

界面源碼:(禪道爲例)
Python自動化之下拉框,隱藏標籤定位 代碼&報錯解決
Python自動化之下拉框,隱藏標籤定位 代碼&報錯解決
排查:
1)因爲是隱藏的,需要操作其可見纔可定位

2)若還是無法定位,請查看前後是否有sleep等待;xpath定位效率會低點。

'''
select標籤定位
使用index
若是操作隱藏的元素的話:style="display: none;";【若不是隱藏的的話不需要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("//*[@id='project']")
Select(project).select_by_index(1)      #從零查第幾個option
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章