gpt4 book ai didi

python - 在 Selenium WebDriver 中使用 "Python"获取此消息 : object has no attribute

转载 作者:太空宇宙 更新时间:2023-11-03 14:24:52 25 4
gpt4 key购买 nike

我在 Pycharm 的 Python 中使用 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_Test2test_Test1EmailEntryPassword

每当我运行代码时,都会遇到此错误:

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

最佳答案

where is your EmailEntry field ?

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

如果你想在其他类或函数中使用一个字段,那么你必须将字段定义为静态。

对于函数来说,概念是相同的。您可以将函数定义为静态,例如

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

对于Python::

class MyClass(object):
def the_static_method(x):
print x
the_static_method = staticmethod(the_static_method)

MyClass.the_static_method(2) # outputs 2

关于python - 在 Selenium WebDriver 中使用 "Python"获取此消息 : object has no attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47710144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com