如何使用selenium在Python和Java中操作隐藏元素?
- 内容介绍
- 文章标签
- 相关推荐
本文共计455个文字,预计阅读时间需要2分钟。
当元素不可见时,Selenium 无法直接对其进行操作。例如,以下情况:
+ Python + 页面主要通过 display:none 控制整个下拉框不可见。此时,若直接操作,Selenium 将无法执行。
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了。例如,下面的情况:
Python
页面主要通过“display:none”来控制整个下拉框不可见。这个时候如果直接操作这个下拉框,就会提示:
from selenium import webdriver from selenium.webdriver.support.select import Select import os,time driver = webdriver.Chrome() file_path = 'file:///' + os.path.abspath('test.html') driver.get(file_path) sel = driver.find_element_by_tag_name('select') Select(sel).select_by_value('opel') time.sleep(2) driver.quit()
exceptions.ElementNotVisibleException:Message:elementnotvisible:Elementisnotcurrentlyvisibleandmaynotbemanipulated
我们需要通过javaScript修改display的值。
本文共计455个文字,预计阅读时间需要2分钟。
当元素不可见时,Selenium 无法直接对其进行操作。例如,以下情况:
+ Python + 页面主要通过 display:none 控制整个下拉框不可见。此时,若直接操作,Selenium 将无法执行。
有时候我们会碰到一些元素不可见,这个时候selenium就无法对这些元素进行操作了。例如,下面的情况:
Python
页面主要通过“display:none”来控制整个下拉框不可见。这个时候如果直接操作这个下拉框,就会提示:
from selenium import webdriver from selenium.webdriver.support.select import Select import os,time driver = webdriver.Chrome() file_path = 'file:///' + os.path.abspath('test.html') driver.get(file_path) sel = driver.find_element_by_tag_name('select') Select(sel).select_by_value('opel') time.sleep(2) driver.quit()
exceptions.ElementNotVisibleException:Message:elementnotvisible:Elementisnotcurrentlyvisibleandmaynotbemanipulated
我们需要通过javaScript修改display的值。

