from selenium import webdriver
import unittest
import HtmlTestRunner
from selenium.webdriver.common.keys import Keys
class Environment(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path="D:\\auto\chromedriver.exe")
def test_login(self):
driver = self.driver
driver.get("htt://localhost/dashboard/user/login")
username = driver.find_element_by_id("uemail")
username.send_keys("xyz@abc.com")
password = driver.find_element_by_id("upwd")
password.send_keys("1234567890")
self.driver.find_element_by_id('upwd').send_keys(Keys.RETURN)
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()
答案 0 :(得分:0)
尝试以下代码:
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class PythonOrgSearch(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path="C:\\Users\\dipak.bachhav\\Downloads\\New folder (2)\\chromedriver_win32\\chromedriver.exe")
def test_search_in_python_org(self):
driver = self.driver
driver.get("http://www.python.org")
self.assertIn("Python", driver.title)
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
def tearDown(self):
self.driver.close()
if __name__ == "__main__":
unittest.main()