标签:implicit def red span 练习 attribute rip 报错 元素
#使元素高亮
def highlight_element(driver, element):
driver.execute_script("arguments[0].setAttribute(‘style‘,arguments[1]);",element,"background:green ;border:2px solid red;")
#等待操作
#准备工作:准备一个元素,封装元素高亮
#sleep() 显性等待
#implicitlywaite() 隐性等待
from slenium_jichu01 import tools
from selenium import webdriver
import time
driver = webdriver.Chrome(0)
driver.get(‘file:///E:/%E6%A1%8C%E9%9D%A2/selenium%E5%85%83%E7%B4%A0%E6%93%8D%E4%BD%9C%E7%BB%83%E4%B9%A0%E4%BE%8B%E5%AD%90/
selenium%E6%BC%94%E7%A4%BA%E4%BE%8B%E5%AD%90/Wait.html‘)
#练习1:不加等待报错
wl=driver.find_element_by_id(‘b‘)
tools.highlight_element(driver,wl)
##练习2:加强制
wl=driver.find_element_by_id(‘b‘).click()
time.sleep(10)
tools.highlight_element(driver,wl)
# #练习3:加隐式
element=driver.find_element_by_id(‘b‘).click()
driver.implicitly_wait(30)
tools.highlight_element(driver,element)
# #练习4:加显示
from selenium.webdriver.support.ui import WebDriverWait
wl=driver.find_element_by_id(‘b‘).click()
element=WebDriverWait(driver,10).until(lambda x:x.find_element_by_css_selector(‘div.red_box‘))
tools.highlight_element(driver,element)
标签:implicit def red span 练习 attribute rip 报错 元素
原文地址:https://www.cnblogs.com/tingting-yang/p/13335794.html