我正在尝试找到一种方法来实现:-使用python的this code -计划一个定时触发-在google chrome上选择一个选项卡
我已经将解决方案复制并粘贴到我的python中,只是为了测试它,但似乎在下面得到了一个URL错误,有人能帮我理解为什么一个变量面临语法错误吗?
下面是我的代码:
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from Common_Methods.GenericMethods import *
import pyautogui #<== need this to click on extension
options = ChromeOptions()
#from stack overflow(https://stackoverflow.com/questions/53172127/click-on-elements-in-chrome-extension-with-selenium?rq=1):
#options.add_argument("--load-extension=" + r"C:\Users\supputuri\AppData\Local\Google\Chrome\User Data\Default\Extensions\fdpohaocaechififmbbbbbknoalclacl\5.1_0") #<== loading unpacked extension
options.add_argument("--load-extension=" + r"/Users/erikwayne/Library/Application Support/Google/Chrome/Profile 2/Extensions/fdpohaocaechififmbbbbbknoalclacl/6.5_0") #<== loading unpacked extension
driver = webdriver.Chrome(
executable_path=os.path.join(chrome_options=options)
url = "https://www.google.com/"
driver.get(url)
# get the extension box
extn = pyautogui.locateOnScreen(os.path.join(GenericMethods.get_full_path_to_folder('autogui_ref_snaps') + "/capture_full_screenshot.png"))
# click on extension
pyautogui.click(x=extn[0],y=extn[1],clicks=1,interval=0.0,button="left")下面是我的错误消息:
MBP:Testing chrome extension erikwayne$ python3 chromeClick_v1.py
File "chromeClick_v1.py", line 15
url = "https://www.google.com/"
^
SyntaxError: invalid syntax扩展调试:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pdb.py", line 1703, in main
pdb._runscript(mainpyfile)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/pdb.py", line 1572, in _runscript
self.run(statement)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/bdb.py", line 587, in run
exec(cmd, globals, locals)
File "<string>", line 1, in <module>
File "/Users/erikwayne/Downloads/Testing chrome extension/chromeClick_v1.py", line 11
url = "https://www.google.com/"
^
SyntaxError: invalid syntax*编辑:尝试从@RafalS修改以下代码,但出现更多错误。
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from Common_Methods.GenericMethods import *
import pyautogui #<== need this to click on extension
import os
options = ChromeOptions()
#from stack overflow(https://stackoverflow.com/questions/53172127/click-on-elements-in-chrome-extension-with-selenium?rq=1):
#options.add_argument("--load-extension=" + r"C:\Users\supputuri\AppData\Local\Google\Chrome\User Data\Default\Extensions\fdpohaocaechififmbbbbbknoalclacl\5.1_0") #<== loading unpacked extension
options.add_argument("--load-extension=" + r"/Users/erikwayne/Library/Application Support/Google/Chrome/Profile 2/Extensions/fdpohaocaechififmbbbbbknoalclacl/6.5_0") #<== loading unpacked extension
driver = webdriver.Chrome(executable_path=os.path.join(chrome_options=options))
url = "https://www.google.com/"
driver.get(url)
# get the extension box
extn = pyautogui.locateOnScreen(os.path.join(get_full_path_to_folder('downloads') + "/capture_full_screenshot.png"))
# click on extension
pyautogui.click(x=extn[0],y=extn[1],clicks=1,interval=0.0,button="left")发布于 2020-05-07 17:30:39
我这样做了,并通过将chrome webdriver安装到一个更容易访问的文件夹路径来进行整理,完全忽略了ospath或GenericMethods。
至于driver = webdriver.Chrome问题,原始代码缺少参数之间的逗号,所以我只是填充了。
driver = webdriver.Chrome(executable_path=os.path.join(r'/Users/USERNAME/Downloads/Testing chrome extension/chromedriver/chromedriver'), options=options)它是被黑在一起的,但它是有效的。
发布于 2020-05-06 13:53:48
driver = webdriver.Chrome(关闭括号
driver = webdriver.Chrome()您还需要import os并替换
GenericMethods.get_full_path_to_folder使用
get_full_path_to_folder因为你做了一个星形导入:
from Common_Methods.GenericMethods import *https://stackoverflow.com/questions/61628228
复制相似问题