There are two programs in < H1 >. The attribute driver = webdriver.Firefox (), has been defined in baidu_main.py and public.py,baidu_main.py, but the attribute value of driver cannot be read normally in public.py. What is the reason for this? I have already written the constructor in baidu_main.py? < / H1 >
< H1 > the baidu_main.py code is as follows: < / H1 >
from selenium import webdriver
from public import Login
class Logintest():
def __init__(self):
self.driver = webdriver.Firefox()
self.driver.get("https://segmentfault.com/")
def test_admin_login(self):
username = "XXXXXX"
password = "XXXXXX"
Login().user_login(self.driver,username,password)
Login().user_logout(self,driver)
abc = Logintest()
abc.test_admin_login()
< H1 > the public.py code is as follows: < / H1 >
from selenium import webdriver
import time
class Login():
def user_login(self, driver, username, password):
try:
self.driver.find_element_by_xpath("/html/body/div[3]/nav/div[2]/div[2]/ul/li/a[1]").click() -sharp
self.driver.find_element_by_xpath("/html/body/div[6]/div/div/div[2]/div/div/div/form/div[2]/input").send_keys(
username) -sharp
self.driver.find_element_by_xpath("/html/body/div[6]/div/div/div[2]/div/div/div/form/div[3]/input").send_keys(
password) -sharp
self.driver.find_element_by_xpath(
"/html/body/div[6]/div/div/div[2]/div/div/div/form/div[4]/button").click() -sharp
except Exception:
print("No found everything, sorry2!")
else:
time.sleep(10)
def user_logout(self, driver):
self.driver.quit()