简体   繁体   English

selenium.common.exceptions.InvalidArgumentException:消息:使用 Selenium Webdriver 通过 Python 调用 get() 时参数无效错误

[英]selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() using Selenium Webdriver through Python

I am making a GUI that asks for a search, goes to Ebay and finds the average price for that search.我正在制作一个要求搜索的 GUI,转到 Ebay 并找到该搜索的平均价格。 But I can't get it to open Selenium.但我无法打开 Selenium。 But just cannot find an answer.但就是找不到答案。 What am I supposed to do?我应该做些什么? Here is my error:这是我的错误:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1885, in __call__
    return self.func(*args)
  File "C:\Users\Jay\AppData\Roaming\Python\Python39\site-packages\appJar\appjar.py", line 3781, in <lambda>
    return lambda *args: funcName()
  File "C:\Users\Jay\Downloads\ebaything\ebay thing.py", line 25, in search
    driver.get("ebay.com")
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: headless chrome=87.0.4280.88)

And here is my code:这是我的代码:

from appJar import gui
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
from time import sleep

def main():
    app = gui("Search, And Find The Average!")
    PATH = "chromedriver.exe"
    
    options = Options()
    options.headless = True
    driver = webdriver.Chrome(PATH, options=options)

    def close():
        app.stop()
    def search():
        Search = app.getEntry("search")
        if Search == '':
            app.infoBox("Invalid", "Invalid Search")
        else:
            driver.get("ebay.com")
            driver.find_element_by_xpath('//*[@id="gh-ac"]').send_keys(search)
            try:
                driver.find_element_by_class('s-item__link')
            except:
                app.infoBox("Invalid", "There Are No Items Matching Your Search.")
    def info():
        app.infoBox("InfoBox", "If It Does Not Work Try Reading The FAQ.")
    app.addEntry("search")
    app.setEntryDefault("search", "Put Your Search Here!")
    app.addButton("Close", close)
    app.addButton("Search", search)
    app.addButton("Info", info)








    app.go()


if __name__ == '__main__':

    main()

If you need anymore information please leave a comment.如果您需要更多信息,请发表评论。

This error message...此错误消息...

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1885, in __call__
.
  File "C:\Users\Jay\Downloads\ebaything\ebay thing.py", line 25, in search
    driver.get("ebay.com")
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
.
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument

  (Session info: headless chrome=87.0.4280.88)

...implies that there was an error in the __init__ while executing the line: ...意味着执行该行时__init__中存在错误:

driver.get("ebay.com")

Instead of passing the partial domain name ebay.com you need to pass the complete url ie https://www.ebay.com/ .而不是传递部分域名ebay.com您需要传递完整的urlhttps://www.ebay.com/


Solution解决方案

Additionally you may also like to pass the absolute path of the ChromeDriver through the Key executable_path .此外,您可能还希望通过Key executable_path传递ChromeDriver的绝对路径。 So the effective code block will be:所以有效的代码块将是:

def main():
    app = gui("Search, And Find The Average!")
    PATH = r'C:\path\to\chromedriver.exe'

    options = Options()
    options.headless = True
    driver = webdriver.Chrome(executable_path=PATH, options=options)

and later然后

driver.get("https://www.ebay.com/") 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.InvalidArgumentException:消息:无效参数错误调用 get() 与使用 Selenium Python 从文本文件读取的 url - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() with urls read from text file with Selenium Python selenium.common.exceptions.InvalidArgumentException:消息:无效参数:使用 selenium webdriver 添加 cookie 时缺少“cookie” - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie' while adding cookies using selenium webdriver selenium.common.exceptions.InvalidArgumentException:消息:无效参数:使用 Selenium 调用 send_keys() 时未找到文件错误 - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error invoking send_keys() using Selenium selenium.common.exceptions.InvalidArgumentException:消息:无效参数:使用 Selenium 上传文件时找不到文件错误 Python - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error while uploading file using Selenium Python Python selenium 用于撰写评论谷歌地图(selenium.common.exceptions.InvalidArgumentException:消息:无效参数:无效定位器) - Python selenium for write review google maps (selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator ) selenium.common.exceptions.InvalidArgumentException:消息:无效参数:在 Selenium 中切换帧时缺少“元素”错误 - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'ELEMENT' error when switching frame in Selenium selenium.common.exceptions.InvalidArgumentException:消息:无效参数:“使用”必须是使用等待和预期条件的字符串 - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string using waits and expected conditions URL 必须是字符串 selenium - selenium.common.exceptions.InvalidArgumentException:消息:无效参数:&#39;url&#39; 必须是字符串 - URL must be a string selenium - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'url' must be a string selenium.common.exceptions.InvalidArgumentException:消息:无效参数:用户数据目录已在使用真正的 Chrome 浏览器时出错 - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use error with real Chrome Browser CssSelector 是我可以用于 shadowroot 的唯一方法吗? selenium.common.exceptions.InvalidArgumentException:消息:无效参数:无效定位器 - Is CssSelector the only way I can use for shadowroot? selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM