'How to locate random id generated by a modal?

I was testing my website using RF. The problem is, every time the modal is opened, a different id(locator) will be set on the textbox that I want to input my text. How do you get value of this locator?

I was supposed to try Get Element Attribute but then it cannot support my problem since it still requires a specific locator.



Solution 1:[1]

In ROBOT Framework (RF), the locator can be accessed by several ways. Please refer and read this link: http://robotframework.org/Selenium2Library/Selenium2Library.html

The most common way to access the locator is by id such as :

Input Text  id:username # Element with id 'username'.
Input Text  id:password # Element with id 'password'. you can also use 'Input Password' keyword.

However, if the 'id' element is so dynamic which it keep changing, then the best alternative is to use either ABSOLUTE XPATH expression or CSS selectors. Install the XPATH add-on in your web browser. For firefox, just install ChroPath.

Then, get the ABSOLUTE Xpath element of that username & password text box. Let's assume we know the absolute xpath expression already, so in ROBOT, you can write like below.

${login_absolute_xpath}=  Set Variable   xpath=/html[1]//div[7]/form[1]/div[1]/input[1]
${password_absolute_xpath}=  Set Variable   xpath=/html[1]//div[7]/form[1]/div[2]/input[1]

Wait Until Page Contains Element   xpath=${login_absolute_xpath}
Input Text   xpath=${login_absolute_xpath}
Input Text   xpath=${password_absolute_xpath}
...

This should works. Please let me know if this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Temizzi