使用Command.GET时,为什么会出现“'str'对象没有属性'execute'”错误?

时间:2019-09-05 07:24:31

标签: selenium-webdriver

使用此代码

from selenium import webdriver
driver = webdriver.Firefox
driver.get("WebDriver","https://www.youtube.com")

它给了我这个错误:

Traceback (most recent call last):
  File "C:/Users/Zohaib/PycharmProjects/FirstPyTesting/youtube.py", line 3, in <module>
    driver.get("WebDriver","http://localhost:81/")
  File "C:\Users\Zohaib\PycharmProjects\FirstPyTesting\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 333, in get
    self.execute(Command.GET, {'url': url})
AttributeError: 'str' object has no attribute 'execute'

那是为什么,我该如何解决?

1 个答案:

答案 0 :(得分:0)

get()

get(url)方法接受字符串形式的url,并定义为:

def get(self, url):
    """
    Loads a web page in the current browser session.
    """
    self.execute(Command.GET, {'url': url})

解决方案

您只需要按如下所示以字符串形式传递url:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.youtube.com")