Python Forum
Invalid argument error thrown. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Invalid argument error thrown. (/thread-20997.html)



Invalid argument error thrown. - pyseeker - Sep-09-2019

Hello,

While running the following code an error thrown with "invalid argument". Appreciate your thoughts.

with open(dataFile, 'r') as urlFile:
    urlFile.readline()
    for url in urlFile:
        driver = webdriver.Chrome('C:\\chromedriver_win32\\chromedriver.exe')
        driver.get('url', )
        link = driver.find_element_by_xpath("/html/body")
        link.click()
    urlFile.close()
Error is as below :

Traceback (most recent call last):
File "C:/Users/spullabhotla/PycharmProjects/AutomateBoringStuff/Chapter-16-SendingEmail&TextMessages/fetchingEmailMessages.py", line 32, in <module>
driver.get('url', )
File "C:\Users\spullabhotla\Documents\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\spullabhotla\Documents\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\spullabhotla\Documents\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: chrome=76.0.3809.132)


RE: Invalid argument error thrown. - luoheng - Sep-10-2019

Line 5: change string 'url' to variable url.


RE: Invalid argument error thrown. - pyseeker - Sep-10-2019

I have tried without the quotes. and it throws the same error.

Traceback (most recent call last):
  File "C:/Users/spullabhotla/PycharmProjects/AutomateBoringStuff/Chapter-16-SendingEmail&TextMessages/fetchingEmailMessages.py", line 32, in <module>
    driver.get(url, )
  File "C:\Users\spullabhotla\Documents\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "C:\Users\spullabhotla\Documents\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\spullabhotla\Documents\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: chrome=76.0.3809.132)



RE: Invalid argument error thrown. - Malt - Sep-10-2019

Here is the code which opens the url and after loading the page, it will kill the driver. Again it will open another session for next link in the file and it will close the driver once loading is done

 
import selenium.webdriver

with open('dataFile.txt', 'r') as urlFile:
   
    for url in urlFile.readlines():
        print(url)
        driver = selenium.webdriver.Chrome(r"C:\Users\Malathi\Downloads\chromedriver_win32\chromedriver.exe")
        driver.get(url, )
        link = driver.find_element_by_xpath("/html/body")
        link.click()
        driver.quit()
     urlFile.close()



RE: Invalid argument error thrown. - pyseeker - Sep-10-2019

It worked very well. But it is just not fast enough as I thought. Working well though.