I have a piece of code that checks if there is an element that is displayed using p then it shows a dialog box but if it can't find it then it checks for another element and if that is displays another dialog box and if that element is not available, then it runs a piece of code.
The code is here.
if driver.find_element_by_class_name('error-code').is_displayed():
LoginError.show()
elif driver.find_element_by_xpath('//*[@id="sample-data-table"]/thead').is_displayed():
QuestionUnavailable.show()
else:
if driver.find_element_by_xpath('//*[@id="radio1"]').is_displayed():
driver.find_element_by_xpath('//*[@id="radio1"]').click()
driver.find_element_by_xpath('//*[@id="btn-savecheck"]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[@id="btn-alert-ok"]').click()
But when I run it, I get this error
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 564, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".error-code"}```
Aucun commentaire:
Enregistrer un commentaire