Python自动化之下拉框,隐藏标签订位 代码&报错解决

python自动化:下拉框定位方法之select标签 style="display: none;"
报错
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulatedpython

界面源码:(禅道为例)
Python自动化之下拉框,隐藏标签订位 代码&报错解决
Python自动化之下拉框,隐藏标签订位 代码&报错解决
排查:
1)由于是隐藏的,须要操做其可见才可定位web

2)若仍是没法定位,请查看先后是否有sleep等待;xpath定位效率会低点。ide

'''
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
相关文章
相关标签/搜索