因为Slenium可以获取访问的页面,所以它可以区分页面上的可见元素与隐含元素。通过is_displayed()可以判断元素在页面上是否可见
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
driver = webdriver.Firefox(firefox_binary='D:/Mozilla Firefox/firefox.exe')
driver.get("http://pythonscraping.com/pages/itsatrap.html")
links = driver.find_elements_by_tag_name('a')
for link in links:
if not link.is_displayed():
print("The link " + link.get_attribute("href") + " is a trap")
fields = driver.find_elements_by_tag_name("input")
for field in fields:
if not field.is_displayed():
print("Do not change value of " + field.get_attribute("name"))
网友评论