[英]Selenium Python webdriver: driver.get() won't accept a variable?
我正在尝试编写一个自动测试脚本,该脚本将对多个URL执行一组操作。 我尝试这样做的原因是因为我正在测试具有多个功能完全相同的前端接口的Web应用程序,因此如果我可以使用单个测试脚本来运行所有这些前端接口并确保基本操作这样,当代码库更改时,这为我节省了大量的回归测试时间。
我当前的代码如下:
# initialize the unittest framework
import unittest
# initialize the selenium framework and grab the toolbox for keyboard output
from selenium import selenium, webdriver
# prepare for the usage of remote browsers
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class Clubmodule(unittest.TestCase):
def setUp(self):
# load up the remote driver and tell it to use Firefox
self.driver = webdriver.Remote(
command_executor="http://127.0.0.1:4444/wd/hub",
desired_capabilities=DesiredCapabilities.FIREFOX)
self.driver.implicitly_wait(3)
def test_010_LoginAdmin(self):
driver = self.driver
# prepare the URL by loading the list from a textfile
with open('urllist.txt', 'r') as f:
urllist = [line.strip() for line in f]
# Go to the /admin url
for url in urllist:
# create the testurl
testurl = str(url) + str("/admin")
# go to the testurl
driver.get("%s" %testurl)
# log in using the admin credentials
def tearDown(self):
# close the browser
self.driver.close()
# make it so!
if __name__ == "__main__":
unittest.main()
当我打印变量testurl
我得到了正确的函数,但是当我尝试使用Python运行脚本时,似乎没有将driver.get("%s" %testurl)
转换为driver.get("actualurl")
。
我希望这是一个语法问题,但是在尝试了所有变体之后,我开始想这是Webdriver的局限性。 可以做到吗?
怎么样
driver.get(testurl)
我认为不需要字符串插值。
我开始觉得这是Webdriver的局限性
当然不是。
以下代码对Selenium 2.44来说对我来说运行良好:
from selenium import webdriver
testurl = 'http://example.com'
driver = webdriver.Firefox()
driver.get('%s' % testurl)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.