• selenium中鼠标单击、双击、右击和键盘输入、键盘组合键应用


    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from time import sleep
    
    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):
            db_btn = self.driver.find_element_by_xpath('/html/body/form/input[2]')
            ActionChains(self.driver).double_click(db_btn).perform()
            #   sleep(1)
            d_btn = self.driver.find_element_by_xpath('/html/body/form/input[3]')
            ActionChains(self.driver).click(d_btn).perform()
            r_btn = self.driver.find_element_by_xpath('/html/body/form/input[4]')
            #   sleep(1)
            ActionChains(self.driver).context_click(r_btn).perform()
            #   sleep(1)
            text= self.driver.find_element_by_xpath('/html/body/form/textarea').get_attribute('value')
            print(text)
            print(text.split(']',num=str.count(text)))
    
        # 鼠标悬停
        def hover(self, by, value):
            element = self.findElement(by, value)
            ActionChains(self.driver).move_to_element(element).perform()
        def test_key(self):
            self.driver.get("https://wwwpre.125339.com.cn")
            sleep(1)
            #   self.driver.find_element_by_xpath('//*[@id="head"]/ul/li[6]/a').click()
            self.driver.find_element_by_link_text('关于我们').click()
            sleep(1)
            #   找到意见反馈
            self.driver.find_element_by_xpath('/html/body/div/div[3]/div/div[1]/div[5]/div/div[2]/div').click()
            #   意见反馈-文本输入框
            yjfk = self.driver.find_element_by_xpath('//*[@id="fb-desc"]')
            #   输入内容
            yjfk.send_keys('中国移动云视讯')
            #   ctrl+a
            yjfk.send_keys(Keys.CONTROL,'a')
            sleep(2)
            #   ctrl+x
            yjfk.send_keys(Keys.CONTROL,'x')
            sleep(2)
            #   ctrl+v
            yjfk.send_keys(Keys.CONTROL,'v')
            sleep(5)
    
    if __name__ == '__main__':
        case = TestCase()
        # case.test_mourse()
        case.test_key()
        case.driver.quit()
  • 相关阅读:
    htpasswd命令
    GitHub访问速度慢的解决方法
    easyui datagrid 首次不加载做法
    Excel日常操作
    补偿接口中循环一直执行sql的问题
    rabbitMq无法消费发送的q的问题
    Unicode与中文转换工具类方法(转)
    idea 一些插件配置
    线程安全的集合类、CopyOnWrite机制介绍(转)
    java websocket学习
  • 原文地址:https://www.cnblogs.com/c-jw/p/13806679.html
Copyright © 2020-2023  润新知