1、使用命令行启动Chrome:
Mac:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -remote-debugging-port=9999
Windows:chrome.exe --remote-debugging-port=9222

2、初始化Chrome:

def setup_method(self):
    chrome_options = webdriver.ChromeOptions()
    chrome_options.debugger_address ="127.0.0.1:9999"

    self.driver = webdriver.Chrome(options=chrome_options)
    self.driver.implicitly_wait(10)

3、编写脚本:

def test_one(self):
    self.driver.get("https://aylasunsea.sunseaiot.com/proreail")
    self.driver.find_element(By.XPATH,
                                 "//*[@id='app']/div[1]/div[2]/div/div[2]/div[2]/ul/li[4]/div[2]/div[1]").click()
    button = self.driver.find_element(By.XPATH, "//*[@id='app']/div[1]/div[2]/div/div[1]/div/ul/li[1]")
    print(button.text)
    button.click()        

    upload_btn = self.driver.find_elements(By.XPATH, '//input[@class="inputSize"]')
    upload_btn[2].send_keys("/Users/parson/Documents/02_Code/PyDemo/images/2.png")
posted on 2020-04-23 10:25  91parson  阅读(557)  评论(0编辑  收藏  举报