zoukankan      html  css  js  c++  java
  • selenium学习笔记10-鼠标单击、双击、右击、键盘输入、键盘组合键的应用

     代码如下:

    from selenium import webdriver
    from time import sleep
    
    # http://sahitest.com/demo
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    
    
    class TestCase(object):
        def __init__(self):
            self.driver = webdriver.Chrome()
            # self.driver.maximize_window()
            # self.driver.get('http://sahitest.com/demo/clicks.htm')
    
        def test_mourse(self):
    
            btn = self.driver.find_element_by_xpath('/html/body/form/input[2]')
            ActionChains(self.driver).double_click(btn).perform()
    
            sleep(2)
    
            btn = self.driver.find_element_by_xpath('/html/body/form/input[3]')
            ActionChains(self.driver).click(btn).perform()
    
            sleep(2)
    
            btn = self.driver.find_element_by_xpath('/html/body/form/input[4]')
            ActionChains(self.driver).context_click(btn).perform()
    
            sleep(5)
    
        def test_key(self):
            self.driver.get('http://www.baidu.com')
            # kw = self.driver.find_element_by_id('kw')
            # kw.send_keys('selenium')
            # kw.send_keys(Keys.CONTROL,'a')
            # sleep(2)
            # kw.send_keys(Keys.CONTROL, 'x')
            # sleep(2)
            # kw.send_keys(Keys.CONTROL, 'v')
            #
            # sleep(2)
    
            e = self.driver.find_element_by_link_text('新闻')
            print(e)
    
            ActionChains(self.driver).move_to_element(e).click(e).perform()
    
    
    
            sleep(2)
    
    
    
    if __name__ == '__main__':
        case = TestCase()
        case.test_key()
  • 相关阅读:
    我的Android平台“人人相册”客户端
    ADT 17及更高版本的混淆变更
    由glBitmap想到OpenGL编程涉及的坐标系
    版本控制之SVN
    工作了,要努力
    50 Most Frequently Used UNIX / Linux Commands (With Examples)
    linux命令分析SED (二)
    SeekBar也玩分段
    TSQL RAND()
    使用WebClient进行上传文件 [ZT]
  • 原文地址:https://www.cnblogs.com/yronl/p/14450943.html
Copyright © 2011-2022 走看看