代码如下
from time import sleep
from selenium import webdriver
from selenium.webdriver import TouchActions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
class TestWait():
def setup(self):
option=webdriver.ChromeOptions()
option.add_experimental_option("w3c",False)
self.driver=webdriver.Chrome(options=option)
self.driver.get("https:www.baidu.com")
self.driver.maximize_window()
self.driver.implicitly_wait(5)
def teardown(self):
self.driver.quit()
def test_touchaction(self):
self.driver.find_element(By.CSS_SELECTOR,"#kw").send_keys("selenium测试学习")
search=self.driver.find_element(By.CSS_SELECTOR,"#su")
action=TouchActions(self.driver)
action.tap(search)
action.perform()
sleep(3)
action.scroll_from_element(search,0,10000).perform()
self.driver.find_element(By.CSS_SELECTOR,"#page a:nth-last-child(0)").click()
sleep(2)
报错信息
StaleElementReferenceException
感觉好像是我页面由于点击刷新了,找不到元素,然后就报错了