zoukankan      html  css  js  c++  java
  • 模块六 web控件交互

     官方文档:

    https://selenium-python.readthedocs.io/api.html

     

     

     

    from time import sleep
    
    import pytest
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    
    
    class TestActions():
        def setup(self):
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(3)
        def teardown(self):
            self.driver.quit()
    
        def test_case_click(self):
            self.driver.get("http://sahitest.com/demo/clicks.htm")
            click_me = self.driver.find_element_by_xpath("//input[@value='click me']")
            dbl_click_me = self.driver.find_element_by_xpath("//input[@value='dbl click me']")
            right_click_me = self.driver.find_element_by_xpath("//input[@value='right click me']")
            action = ActionChains(self.driver)
            action.click(click_me)
            sleep(3)
            action.context_click(right_click_me)
            sleep(3)
            action.double_click(dbl_click_me)
            sleep(3)
            action.perform()
    
    if __name__ == '__main__':
        pytest.main('-v','-s','test_click.py')

     

     

    from time import sleep
    import pytest
    
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    
    
    class TestCase():
        def setup(self):
            self.driver = webdriver.Chrome()
    
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()
    
        def teardown(self):
            self.driver.quit()
        @pytest.mark.skip
        def test_case_clike(self):
            self.driver.get("http://sahitest.com/demo/clicks.htm")
            ele_click = self.driver.find_element_by_xpath("//input[@value='click me']")
            ele_doubleclick = self.driver.find_element_by_xpath("//input[@value='dbl click me']")
            ele_rightclick = self.driver.find_element_by_xpath("//input[@value='right click me']")
            action = ActionChains(self.driver)
            action.click(ele_click)
            action.context_click(ele_rightclick)
            action.double_click(ele_doubleclick)
            sleep(3)
            action.perform()
            sleep(3)
    
        @pytest.mark.skip
        def test_moveto(self):
            self.driver.get('https://www.baidu.com/')
            ele = self.driver.find_element_by_link_text("设置")
            action = ActionChains(self.driver)
            action.move_to_element(ele)
            action.perform()
            sleep(5)
        def test_keys(self):
            self.driver.get("https://www.baidu.com/")
            ele = self.driver.find_element_by_id("kw").click()
            action = ActionChains(self.driver)
            action.send_keys("uesername").pause(2)
            action.send_keys(Keys.SPACE).pause(2)
            action.send_keys("tom").pause(2)
            action.send_keys(Keys.BACK_SPACE).perform()
            sleep(3)

     

     

    from time import sleep
    
    from selenium import webdriver
    from selenium.webdriver import TouchActions
    
    
    class TestTouch():
        def setup(self):
            option = webdriver.ChromeOptions()
            option.add_experimental_option('w3c',False)
            self.driver = webdriver.Chrome(options= option)
            self.driver.implicitly_wait(5)
    
        def teardown(self):
            self.driver.quit()
    
        def test_touchaction(self):
            self.driver.get("http://www.baidu.com")
            el = self.driver.find_element_by_id("kw")
            el_search = self.driver.find_element_by_id("su")
            el.send_keys("selenium测试")
            action = TouchActions(self.driver)
            action.tap(el_search)
            action.perform()
            sleep(3)
            action.scroll_from_element(el,0,10000).perform()

    表单操作

     

  • 相关阅读:
    PAT (Basic Level) Practice (中文)1002 写出这个数 (20 分)
    PAT (Advanced Level) Practice 1001 A+B Format (20 分)
    BP神经网络(原理及MATLAB实现)
    问题 1676: 算法2-8~2-11:链表的基本操作
    问题 1744: 畅通工程 (并查集)
    链表的基本操作(创建链表,查询元素,删除元素,插入元素等)
    问题 1690: 算法4-7:KMP算法中的模式串移动数组
    问题 1923: [蓝桥杯][算法提高VIP]学霸的迷宫 (BFS)
    Hdu1372 Knight Moves (BFS)
    Problem 2285 迷宫寻宝 (BFS)
  • 原文地址:https://www.cnblogs.com/hantongxue/p/14397564.html
Copyright © 2011-2022 走看看