python - selenium 打开浏览器控制台并使用 python 粘贴一些 javascript 代码
问题描述
我有一个javascript,我想在页面加载时将其放入控制台,但我无法在python中使用selenium打开控制台我可以使用它访问devtoos--auto-open-devtools-for-tabs
但无法打开控制台。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException
import os
import time
from urllib.parse import quote_plus
driverPath = "chromedriver.exe"
dataPath = "whatsapp-assistant-bot-master/Data"
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=" + dataPath)
options.add_argument("--auto-open-console-for-tabs=" + dataPath)
driver = webdriver.Chrome(options=options, executable_path=driverPath)
driver.get('http://google.com')
print('Please Scan the QR Code and press enter')
driver.find_element_by_id("gsr").send_keys(Keys.F12)
input()
driver.quit()
解决方案
回答到这里,不用打开控制台,可以通过selenium运行你的js代码
推荐阅读
- java - 如何使用插件 DevKit 在项目树中设置文件突出显示颜色
- amazon-web-services - 从本地运行 AWS CLI,而不将凭证存储在本地
- url - 如何在没有 SVN 浏览器的情况下进入 Intellij 文件的 SVN 链接?
- android - DialogFragment 占用整个屏幕宽度
- angular - 将开源库用于应用程序的关键功能
- database - 数据库规范化步骤
- php - Mailchimp 类不存在
- javascript - JavaScript 自动完成级联下拉/输入
- html - flexbox 列中的重叠 div
- performance - Fortran 中的这些数组初始化方法是否同样快?