from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import unittest
class LoginTest(unittest.TestCase):
def setUp(selfself):
self.driver = webdriver.Chrome(executable_path='C:\Users\pepe2\Downloads\chromedriver_win32\chromedriver.exe')
driver.maximize_window()
self.driver.get("https://account.microsoft.com/account")
driver.find_element_by_id("meControl").click()
def test_Login(self):
emailFieldID = "email"
passFieldID = "pass"
LoginButtonID = "idSIButton9"
emailFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(emailFieldID))
passFieldElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name(passFieldID))
LoginButtonElement= WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id(LoginButtonID))
emailFieldElement.clear().send_keys("************")
passFieldElement.clear().send_keys("***********")
LoginButtonElement.click()
def tearDown(self):
self.driver.quit()
if __name__ == '_main_':
unittest.main()
You're calling this indirectly through a class, not in main. Hence, (__name__ == '_main_')
will always be False.
Notice what happens when I run this code by itself.
if __name__ == '_main_':
print ('something 1')
if __name__ == '__main__':
print ('something 2')
The result is,
something 2
There should be double underscores on either side of 'main'.
I've changed this line:
self.driver = webdriver.Chrome(executable_path=r'C:\Users\pepe2\Downloads\chromedriver_win32\chromedriver.exe')
(The path must be marked as a raw string because it contains backslashes.)
I suspect that the one line in the main program should be,
LoginTest.main()
because LoginTest
derives from unittest
. However, although the script now runs it throws an error claiming that LoginTest
lacks the attribute `Main'.
It's up to you now.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.