Search code examples
pythonseleniumselenium-webdrivergetappjar

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.


Solution

  • 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 i.e. 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/")