执行页面滑动时报错 Cannot call non W3C standard command while in W3C mode
解决方式如下:
在实例化driver的时候添加option
class uitest(unittest.TestCase): @classmethod def setUpClass(self): option=webdriver.ChromeOptions() option.add_experimental_option('w3c',False) self.driver = webdriver.Chrome(options=option) self.driver.maximize_window() self.driver.implicitly_wait("1") self.driver.get("https://www.baidu.com/")
页面内滑动到底部的代码实现 def test3(self): #在页面内滑动到底部点击下一页按钮 el=self.driver.find_element(By.XPATH,'//*[@id="su"]') action1=TouchActions(self.driver) action1.scroll_from_element(el,0,100).perform() self.driver.find_element(By.XPATH,'//*[@class="page-inner_2jZi2"]//a[last()]').click()