Reputation: 43
I have 2 functions in my code, one that makes the driver object and the other one makes the driver go to an url and so on. I'm trying to pass the driver the first function creates to the seconds one. This is my code :
import urllib3
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = 'https://www.example.com'
def drivercreate():
options = Options()
options.add_argument("user-data-dir=C:\\Users\\me\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("profile-directory=Profile 19")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=options)
return driver
def urlget():
driver.get(url)
However this tells me that the driver variable is not defined rather than going to an url with the get command. I have tried putting the drivercreate function into a class and passing it to the urlget function however that just said that the function has no attribute get. I'm a newbie so I'm appreciative of any help on the matter :)
Upvotes: 0
Views: 846
Reputation: 1657
You should have an additional parameter in your second function, so you can pass driver to it as an argument.
def urlget(driver):
driver.get(url)
After corrections are done, you can try the following.
driver = drivercreate()
urlget(driver)
Upvotes: 2