我可以通过 Selenium 打开 Chrome,但无法模拟按键(特别是 F12,因为我想打开 Inspect 并最终使用移动浏览器,就像这样),但我可以手动执行此操作,即打开 Chrome 并按 F12,我希望能够使用 Selenium 自动化这部分。我当前的代码如下所示 -
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome('/Users/amigo/Documents/pet_projects/selenium/chromedriver')
driver.get('https://www.google.com')
ActionChains(driver).send_keys(Keys.F12).perform()
Run Code Online (Sandbox Code Playgroud)
虽然代码运行没有任何错误,但我没有看到在浏览器上打开检查。任何建议和帮助表示赞赏!先感谢您。
mobile selenium python-3.x google-chrome-devtools selenium-chromedriver