使用Selenium 3.0.2与python 3.5.1和firefox 52,以下selenium代码抛出错误:
AttributeError:'WebDriver'对象没有属性'getCurrentUrl'
有关为何发生这种情况或使用什么而不是使用getCurrentUrl的任何想法?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import unittest, time, re
class TestURL(unittest.TestCase):
def setUp(self):
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities.update({'acceptInsecureCerts': True})
binary = FirefoxBinary('/var/lib/firefox/firefox')
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
self.driver = webdriver.Firefox(firefox_binary=binary,firefox_profile=profile, capabilities=capabilities)
self.driver.implicitly_wait(30)
self.base_url = "http://www.python.org"
self.verificationErrors = []
def test_load(self):
driver = self.driver
driver.get(self.base_url)
url = driver.getCurrentUrl()
try: self.assertEqual("http://www.python.org", url)
except AssertionError as e: self.verificationErrors.append(str(e))
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
错误:
E
======================================================================
ERROR: test_load (__main__.TestURL)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 26, in test_load
url = driver.getCurrentUrl()
AttributeError: 'WebDriver' object has no attribute 'getCurrentUrl'
----------------------------------------------------------------------
Ran 1 test in 10.202s
FAILED (errors=1)