我正在尝试在selenium webdriver中创建自定义函数以执行特定操作。我需要从另一个文件中调用这些函数。
我首先尝试使用此代码打开Google主页:
from selenium import selenium
import unittest, time, re
from selenium import webdriver
seed_url="http://www.google.com"
class test(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox", "https://www.google.com/")
self.selenium.start()
def test_urlfunctions(self):
sel = self.selenium
sel = webdriver.Firefox()
sel.get(seed_url)
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
接下来我尝试创建一个打开URL的功能(这是一个非常基本的功能,我将做更多的操作,比如将来存储网页的html源代码):
from selenium import selenium
import unittest, time, re
from selenium import webdriver
seed_url="http://www.google.com"
class test(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*firefox", "https://www.google.com/")
self.selenium.start()
def test_urlfunctions(self):
sel = self.selenium
sel = webdriver.Firefox()
def open_url(url):
sel.get(url)
open_url(seed_url)
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
我需要从另一个文件调用open_url函数。我该如何导入文件?我是python的类/函数概念的新手。请帮忙。
谢谢, 狡猾