一、模拟手机打开页面(H5测试)
1 from selenium import webdriver
2 mobile_emulation = {'deviceName':'iPhone X'}
3 options = webdriver.ChromeOptions()
4 options.add_experimental_option('mobileEmulation',mobile_emulation)
5 driver = webdriver.Chrome(chrome_options=options)
6 driver.maximize_window()
7 driver.get("http://www.baidu.com")
二、鼠标、键盘操作(只解释拖拽和Enter,其他需要自己补充)
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
driver = webdriver.Chrome
ActionChains(driver).drag_and_drop(element1,element2).perform() #拖拽
driver.find_element_by_xpath(element).send_keys(Keys.ENTER) #Enter
三、starts-with、contains定位
1
2 //div[starts-with(@style,'border')]
3
4
5 //div[contains(@class,'success')]
//*[contains(text(),'contains')]