How to identify the Linear layout textbox element of OTP verification in robot framework

For static otp verification code(For ex. 1234), xpath of the Linear layout textbox element (verification code) is not found and getting error that “xpath not found”.

Initially user name and password is given and after clicking on sign in, it navigates to this screen and asking for OTP verification code. Here its a linear layout textbox with four inputs for verification code.
while writing robot script with keyword ‘Input Text’ using xpath of the textbox, the element is not found.

Need any suggestion to overcome this error.

Here I have attached the screenshot of the webpage.

Please paste here the xpath locator you used.
There are four input fields, how do you distinguish them?

Hi Keerthana,

Always a good idea to show what you have tried, you said you got “xpath not found" but didn’t show which xpath that was for?

here is the xpaths I would use as a first try:

(//input[@type="tel" and @maxlength="1"])[1]
(//input[@type="tel" and @maxlength="1"])[2]
(//input[@type="tel" and @maxlength="1"])[3]
(//input[@type="tel" and @maxlength="1"])[4]

the combination of type=tel and maxlength=1 is probably unique to these 4 fields, so that should get you to those fields and then it’s just a matter of selecting which one you want.

Hope that helps,

Dave.

Input Text xpath=//[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[1]/input 1
Input Text xpath=//
[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[2]/input 2
Input Text xpath=//[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[3]/input 3
Input Text xpath=//
[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[4]/input 4

Thanks for your xpath suggesstion. here are the one i used for my robot framework

Input Text xpath=//[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[1]/input 1
Input Text xpath=//
[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[2]/input 2
Input Text xpath=//[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[3]/input 3
Input Text xpath=//
[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[1]/div/div[4]/input 4

Hi Keerthana,

Yeah that type of xpath is always problematic, see my comment in this thread:

I suggest you take the time to learn to write good xpaths, it will save you a lot of pain in maintaining your test cases.

Dave.

Hi dave,

these xpaths does not help me.

Error:

InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //input[@type=“tel” and @maxlength=“1”])[1] because of the following error:
SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//input[@type=“tel” and @maxlength=“1”])[1]’ is not a valid XPath expression.

sure thanks Dave

Hi Keerthana,

That’s odd, I just checked and this (//input[@type="tel" and @maxlength="1"])[1] is a valid xpath can you show the full line from your robot file?

Dave.

Hi Dave,

Input Text      xpath=//input[@type="tel" and @maxlength="1"])[1]    1
Input Text      xpath=//input[@type="tel" and @maxlength="1"])[2]    2
Input Text      xpath=//input[@type="tel" and @maxlength="1"])[3]    3
Input Text      xpath=//input[@type="tel" and @maxlength="1"])[4]    4

Hi Keerthana,

First I noticed you are missing the opening “(” from the xpath I gave you, you will need that.

I’m guessing your using SeleniumLibrary? The syntax for using xpaths in the documentation says that you should use xpath://your/xpath

Input Text      xpath:(//input[@type="tel" and @maxlength="1"])[1]    1
Input Text      xpath:(//input[@type="tel" and @maxlength="1"])[2]    2
Input Text      xpath:(//input[@type="tel" and @maxlength="1"])[3]    3
Input Text      xpath:(//input[@type="tel" and @maxlength="1"])[4]    4

but you also can use the Implicit XPath strategy which is what I normally use

Input Text      (//input[@type="tel" and @maxlength="1"])[1]    1
Input Text      (//input[@type="tel" and @maxlength="1"])[2]    2
Input Text      (//input[@type="tel" and @maxlength="1"])[3]    3
Input Text      (//input[@type="tel" and @maxlength="1"])[4]    4

Dave.

Hi Dave,

Element with locator ‘xpath:(//input[@type=“tel” and @maxlength=“1”])[1]’ not found.

Hi Keerthana,

That’s weird can you check the xpath outside RF, in the dev tools screen in your screen shot you should be able to click the element then do a find (control-f or command-f on mac) and past the xpath I gave you into the search field to check it.

also check the double quotes are actually double quotes and not some other character, the ones in your reply are not " but “.

Dave.

Throwing my 2 cents here. Are you sure that HTML elements you are trying to access are not inside a frame ?

Hi,
yes i am sure, the elements are not inside a frame

Are you maybe trying access elements before they are visible ? Page still loading or something ?

Hi, thanks for your ideas.

They are actually double quotes and not some other character. your xpath identifies the element in dev tools.

Another element is the verify button and also i am not able to identify the verify button now. getting similar error for verify button

error:

Element with locator ‘xpath://*[@id=“root”]/div/div[1]/div[2]/div/div[1]/div/div[2]/div/div[3]/button’ not found.

Hi Keerthana,

You said they are not in a frame, but what about an iframe?

is it possible for me to access this page? If so I’ll have a better chance of figuring it out.

Dave.

Elements are visible and page gets loaded

It is a different thing what you observe with your eyes compared how automation works :wink: you might be searching for element before dom has been updated with the new information.

Have you tried to use Wait Until Element Is visible (//input[@type=“tel” and @maxlength=“1”])[1] before actually using Input Text ?

And you could be locating the button with something like…
//button[text()=“VERIFY”] ← verify might be written in different ways, I mean css could change the appearance of the text so look into inspector how it is written