So, I have an alert that has multiple span elements with different error messages. I need to test if a specified message is contained in that alert. For example, in the screenshot below, one of the span elements contains the "The email field is required" message. I tried implementing it in Python and then use it as a keyword in RobotFramework, but i've got stuck at finding the current browser instance. The Parser.py file contains:
from selenium.webdriver.common.by import By
from selenium import webdriver
def parse_alert_msg(elements, message):
alerts = driver.find_elements(By.XPATH, elements)
for item in alerts:
if item.text == message:
return True
return False
This is what i have in my robot file:
Test Function
Open Website
Login Successfully as ${UserName} ${Password}
${message} Parser.Parse Alert Msg //div[@class='alert-content']/span[@class='alert-description'] You have logged in.
Run Keyword If ${message}=${FALSE} Fail There is no such span with that text.
[Teardown] Close Browser