Я сталкиваюсь с очень странной проблемой, что модульный тест python по 2-му методу не работает.
Ниже приведен код
from selenium import webdriver
import unittest
import time
class PIM_config(unittest.TestCase):
@classmethod
def setUpClass(cls):
print(" Open Application")
cls.driver = webdriver.Chrome(executable_path='/Library/Python/2.7/site-packages/chromedriver')
cls.driver.get("https://opensource-demo.orangehrmlive.com/")
def test_Valid_Login(self):
self.driver.find_element_by_id("txtUsername").send_keys("admin")
self.driver.find_element_by_id("txtPassword").send_keys("admin123")
self.driver.find_element_by_id("btnLogin").click()
time.sleep(5)
def test_PVMConfirgOption(self):
print(" Hello")
self.driver.find_element_by_xpath("//a[@id='welcome']").click()
@classmethod
def tearDownClass(self):
print("Close Application")
if __name__ == "__main__":
unittest.main()
Сообщение об ошибке на консоли:
Error
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 59, in testPartExecutor
yield
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/case.py", line 615, in run
testMethod()
File "/Users/reenupanwar/PycharmProjects/Web_Python_Automation/MatchStatus/PIM_confirg.py", line 23, in test_PVMConfirgOption
self.driver.find_element_by_xpath("//a[@id='welcome']").click()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 258, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 712, in find_element
{'using': by, 'value': value})['value']
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@id='welcome']"}
(Session info: chrome=73.0.3683.86)
(Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Mac OS X 10.12.6 x86_64)
Assertion failed
Close Application
Ran 2 tests in 15.090s
FAILED (errors=1)
Process finished with exit code 1
Assertion failed
Assertion failed
Мой XPath на 2-х методах тестирования верен на 100%, и он работает, когда я использовал ту же строку кода в первом методе.Но при использовании второго метода я столкнулся с вышеуказанным вопросом.Пожалуйста, предложите.