我收到此错误:NameError:未定义名称'driver' 当我在python中运行代码时。 我想要的是将导航模块返回到我的页面上。
I try some code like this:
driver = webdriver.Firefox()
from selenium import webdriver
driver = webdriver.Chrome(executable_path= r'C:\\Utility\\BrowserDrivers\\chromedriver.exe')
我的代码:
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();
我想要的是,对于程序的最后一部分,我会自动使用driver.navigate()。back()函数返回。没有下面的错误
答案 0 :(得分:1)
将driver.navigate().back();
更改为browser.navigate().back();
。