Home > Mobile >  Web driver "get" method error, when receives the url from the property of class instance o
Web driver "get" method error, when receives the url from the property of class instance o

Time:10-20

I want to organize my urls for the testing project, so I tried to create a separate class or dictionary to store urls, but whenever I tried to call a "driver.get(pages.url)" method I get an error. Although if you pass the url from a variable or a string directly, everything works. I can't understand where is the problem. Could someone help? The code:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options

class Pages:
    basic_url:str = 'google.com'
    translate:str = 'translate.'   basic_url
    maps:str = 'www.'   basic_url   '/maps'

pages = Pages()
print(pages.translate)
print(type(pages.translate))

chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(executable_path=ChromeDriverManager().install()),options=chrome_options)
wait = WebDriverWait(driver, 60)

driver.maximize_window()

driver.get(pages.translate)

The error:

'Traceback (most recent call last):
  File "E:\Projects\Python\portal_UI_testing_automation\ptn.py", line 23, in <module>
    driver.get(pages.translate)
  File "E:\portal_UI_testing_automation\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in get
    self.execute(Command.GET, {'url': url})
  File "E:\portal_UI_testing_automation\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "E:\portal_UI_testing_automation\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
  (Session info: chrome=106.0.5249.119)'

CodePudding user response:

Print your url before passing it to driver.get to make sure its valid. As some of the comments suggest try adding http/https.

CodePudding user response:

I think you are missing https:// in the URL

This is the correct answer. Thanks Sighil, and others.

  • Related