gpt4 book ai didi

python - "self"在 selenium python 代码中做什么?

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

<分区>

Possible Duplicate:
Python ‘self’ explained

我刚刚在 selenium 文档的帮助下编写了如下代码,但对 self 做的一些方法 argument list 感到困惑?为什么我需要导入 unittest 类?

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

class PythonOrgSearch(unittest.TestCase):

def setUp(self):
self.driver = webdriver.Firefox()

def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("selenium")
elem.send_keys(Keys.RETURN)
self.assertIn("Google", driver.title)

def tearDown(self):
self.driver.close()

if __name__ == "__main__":
unittest.main()

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