在Selenium WebDriver中使用“Python”得到以下消息:object has no attribu

2024-09-20 22:53:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python的Pycharm中使用Selenium WebDriver,其中我使用的类有2个测试函数。在

class goodsweb(unittest.TestCase):

    def setUp(self):
        driverlocation ="/Users/new/Documents/Learning/Drivers/selenium-2.53.1/py/selenium/webdriver/chromedriver"
        os.environ["webdriver.chrome.driver"] = driverlocation
        self.driver = webdriver.Chrome(driverlocation)

    def test_Test1(self):
        self.EmailEntry = input("Please Enter Email Address: ")
        self.EmailAddress.send_keys(self.EmailEntry)
        self.Password.clear()
        self.password='12345678'
        self.Password.send_keys(self.password)

    def test_Test2(self):
        self.LoginEmail = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='email']")
        self.LoginEmail.clear()
        self.LoginEmail.click()
        self.LoginEmail.send_keys(self.EmailEntry)

        self.LoginPassword = driver.find_element_by_xpath("//*[@id='sign_form-default']//div[1]/input[@type='password']")
        self.LoginPassword.clear()
        self.LoginPassword.click()
        self.LoginPassword.send_keys(self.password)

现在我想要的是在test_Test2中获得EmailEntry和{}的test_Test1的访问权

每当我运行代码时,都会出现以下错误:

AttributeError: 'goodsweb' object has no attribute 'EmailEntry'


Tags: testselfsendinputdefdriverpasswordkeys
1条回答
网友
1楼 · 发布于 2024-09-20 22:53:24

where is your EmailEntry field ?

在goodsweb类中无法访问。在该类中声明或定义为静态,以便可以在任何其他类中使用。在

如果要在其他类或函数中使用一个字段,则必须将该字段定义为静态字段。在

函数的概念是相同的。您可以将函数定义为静态类

public static void main(){
     // your logic
}

对于python::

^{pr2}$

相关问题 更多 >

    热门问题