Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x str对象没有属性';获取';_Python 3.x_Selenium - Fatal编程技术网

Python 3.x str对象没有属性';获取';

Python 3.x str对象没有属性';获取';,python-3.x,selenium,Python 3.x,Selenium,我在selenium python中使用unittest示例 尝试谷歌没有得到正确的解决方案 from selenium import webdriver import unittest #import HtmlTestRunner class googlesearch(unittest.TestCase): driver = 'driver' @classmethod def setupClass(self): self.driver = w

我在selenium python中使用unittest示例

尝试谷歌没有得到正确的解决方案

from selenium import webdriver
import unittest
#import HtmlTestRunner




class googlesearch(unittest.TestCase):
    driver = 'driver'


    @classmethod
    def setupClass(self):
        self.driver = webdriver.Chrome(chrome_options=options)
        self.driver.implicitly_wait(10)
        self.driver.maximize_window()


    def test_search_automationstepbystep(self):
        self.driver.get("https://google.com")
        self.driver.find_element_by_name("q").send_keys("Automation Step By step")
        self.driver.find_element_by_name("btnk").click()


    def test_search_naresh(self):
        self.driver.get("https://google.com")
        self.driver.find_element_by_name("q").send_keys("Naresh")
        self.driver.find_element_by_name("btnk").click()


    @classmethod
    def teardownClass(self):
        self.driver.close()
        self.driver.quit()
        print("Test completed")

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

正如前面提到的@Error-Syntactical懊悔,由于类中的第一行代码,驱动程序是一个字符串


如果您计划全局访问驱动程序,请确保将
驱动程序
声明为全局。

驱动程序='driver'
因此
驱动程序
是一个
str
。您对在字符串上调用
get
有什么期望?