- 此问题在此处已有答案**:
How to create a new instance from a class object in Python(6个答案)
3天前关闭。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from self import self
class Demo:
def new_login(self):
driver = webdriver.Chrome()
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login")
driver.maximize_window()
def new_tests(self):
self.driver.find_element(By.XPATH, "//input[@placeholder='Username']").send_key("Admin")
obj = Demo
obj.new_login(self)
obj.new_tests(self)
尝试运行此代码时,我遇到了一个错误:Error: AttributeError: 'function' object has no attribute 'driver'
如何解决此问题?
1条答案
按热度按时间qpgpyjmq1#
您的代码应如下所示: