高级控件交互方法3(web)

'''TouchAction用法'''
from selenium import webdriver
from selenium.webdriver import TouchActions
import time

class TestTouchAction():
    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('https://www.baidu.com/?tn=02003390_24_hao_pg')
        #定位输入框元素
        el=self.driver.find_element_by_id('kw')
        #搜索框输入selenium
        el.send_keys('selenium')
        #定位搜索元素
        el_search=self.driver.find_element_by_id('su')
        action=TouchActions(self.driver)
        #点击搜索
        action.tap(el_search)
        #滑到页面最下端
        action.scroll_from_element(el,0,10000)
        action.perform()
        time.sleep(3)

if __name__ == '__main__':
    TestTouchAction()
'''表单操作form里'''
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestForm():
    def setup(self):
        self.driver=webdriver.Chrome()
        self.driver.implicitly_wait(5)

    def teardown(self):
        self.driver.quit()

    def test_form(self):
        self.driver.get('http://testerhome.com/account/sign_in')
        self.driver.find_element(By.ID,'user_login').send_keys('123')
        self.driver.find_element(By.ID,'user_password').send_keys('456')
        self.driver.find_element(By.XPATH,'//*[@id="new_user"]/div[3]/div/label').click()
        self.driver.find_element(By.XPATH,'//*[@type="submit"]')
        time.sleep(3)

if __name__ == '__main__':
    TestForm()