selenium进阶1

解决登录问题

1. Cookie

打开已经启动的浏览器进程

https://github.com/ChromeDevTools/devtools-protocol

remote debug

windows:     chrome.exe --remote-debugging-port=9222

        chrome_options = webdriver.ChromeOptions()
        chrome_options.debugger_address = "127.0.0.1:9222"
        cls.driver = webdriver.Chrome(options=chrome_options)    

 注入js

execut_script:执行js,prameters: js, args

print(self.driver.execute_script("console.log('hello from selenium')"))
print(self.driver.execute_script("return document.title;"))
self.driver.execute_script("arguments[0].click();", el)
 

return:

print(self.driver.execute_script("console.log('hello from selenium')"))
print(self.driver.execute_script("return document.title;"))

文件上传

找到元素直接send_keys

某元素不可见,expected_conditions.invisibility_of_element_located

多浏览器管理

原文地址:https://www.cnblogs.com/SomnusWho/p/14156744.html