What is required to pass URL as arguments in selenium python

I'm writing a selenium python script for automation. Want to pass IP as an argument to create URLs to be used in the script.

node_ip = sys.argv[1]
app_url = str("https//"+node_ip+":5200/admin/")
def site_login():
    browser.get(app_url)

But when i run the script i get the following error :

# python3 test.py 192.168.20.10
  File "test.py", line 81, in <module>
    site_login()
  File "test.py", line 33, in site_login
    browser.get(app_url)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/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=78.0.3904.97)

Could you help fix this ?

1 answer

  • answered 2019-11-14 23:21 jayg_code

    Try using f'http://{node_ip}:5200/admin' or any string formatting methods in Python. Personally I haven't seen much examples where str() is used except when converting a non-string variable to string (i.e., f'I counted {str(x)} times!').