鼠标单击、双击、右击、键盘输入、键盘组合键的应用

image.png

实例ActionChains、Keys

code:

from prompt_toolkit.keys import Keys
from selenium import webdriver
from time import sleep
import os

#http://sahitest.com/demo
from selenium.webdriver import ActionChains


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_mouse(self):
        #ActionChains
        btn = self.driver.find_element_by_xpath('/html/body/form/input[2]')
        ActionChains(self.driver).double_click(btn).perform()
        sleep(2)
        btn2 = self.driver.find_element_by_xpath('/html/body/form/input[3]')
        ActionChains(self.driver).click(btn2).perform()

    def test_key(self):
        # ActionChains
        self.driver.get('http://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')


if __name__ == '__main__':
    case = TestCase()
    #case.test_mouse()
    case.test_key()

你可能感兴趣的:(鼠标单击、双击、右击、键盘输入、键盘组合键的应用)