简体   繁体   中英

NameError: name 'driver' is not defined for Selenium

I get this error: NameError: name 'driver' is not defined When i run my code in python. What i want is call the module Navigation for go back on my page.

I try some code like this:
driver = webdriver.Firefox()

from selenium import webdriver
driver = webdriver.Chrome(executable_path= r'C:\\Utility\\BrowserDrivers\\chromedriver.exe')

My code:

from selenium import webdriver   

# For using sleep function because selenium 
# works only when the all the elemets of the 

# page is loaded. 
import time 

from selenium.webdriver.common.keys import Keys 
from selenium import webdriver
# Apertura firefox (OK)
browser = webdriver.Firefox() 
browser.get('https://www.presearch.org/login') 


# Inserimento mail (OK)

user = browser.find_elements_by_xpath('/html/body/div[1]/div[2]        /div/div[2]/div[3]/div[1]/form/div[1]/input') 
user[0].click() 
user[0].send_keys('my_mail') 

# Inserimento password (OK) 


user = browser.find_elements_by_xpath('/html/body/div[1]/div[2]        /div/div[2]/div[3]/div[1]/form/div[2]/div/input') 
user[0].click() 
user[0].send_keys('My_pass')

LOG = browser.find_elements_by_xpath('/html/body/div[1]/div[2]  /div/div[2]/div[3]/div[1]/form/div[3]/div[2]/button') 
LOG[0].click() 
print("Login Sucessfull") 
time.sleep(5) 


# Inserimento testo + coin (OK) 
elem = browser.find_element_by_xpath("//*[@id=\"search\"]")  
elem.click() 
elem.clear() 

elem.send_keys("Geeks for geeks ") 

elem.send_keys(Keys.RETURN) 

print("Testo inserito, coin guadagnato") 

# Ritorno pagina

driver.navigate().back();

What i wannt is, for the last part of my program, automaticly go back with the function driver.navigate().back(); without get the error below

Change driver.navigate().back(); to browser.navigate().back(); .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM