简体   繁体   中英

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. But I can't get it to open 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:

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/ .


Solution

Additionally you may also like to pass the absolute path of the ChromeDriver through the Key executable_path . 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/") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question selenium.common.exceptions.InvalidArgumentException: Message: invalid argument error invoking get() with urls read from text file with Selenium Python selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'cookie' while adding cookies using selenium webdriver selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error invoking send_keys() using Selenium selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: File not found error while uploading file using Selenium Python Python selenium for write review google maps (selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator ) selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing 'ELEMENT' error when switching frame in Selenium selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string using waits and expected conditions URL must be a string selenium - selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'url' must be a string selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use error with real Chrome Browser 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