Element not visible sometimes with Robot Framework - robotframework

I am working with Robot FW for the first time and am facing an issue - one of the test cases requires a modal confirmation dialog to open, after which a button "Delete" is pressed. The keyword for the test case is given below:
Delete Test Data
[Arguments] ${name}
Wait Until Element Is Visible xpath=//tr[#item_name='${name}']
Click Button xpath=//tr[#item_name='${name}']//button[#class='btn btn-sm btn-danger']
Wait Until Element Is Visible id=deleteItem timeout=10
Click Button Delete
Wait Until Element Is Not Visible xpath=//tr[#item_name='${name}']
The line Wait Until Element Is Visible id=deleteItem timeout=10 is causing all the problems. Sometimes the element is visible within the time limit, at other times it is not. I increased the timeout to 10 seconds, but it does not fix the problem. How can I make the dialog appear each time without failing? Any help is appreciated, thanks!

My approach is to change the 'Wait Until Element is Visible' to Wait Until Page Contains Element like below..
${check_element}= Run Keyword and Return Status Wait Until Page Contains Element locator 10s
Run Keyword If '${check_element}' == 'True' Click Element locator
The reason to change to this keyword is that sometimes, the element is already loaded and available in DOM or page but the visibility is hidden. This intermittent weird thing happen to me some times.

I have also faced same kind of failures.
I am able to solve this problem by using "Wait Until Keyword Succeeds" keyword.
"Wait Until Keyword Succeeds" keyword, the waited condition is checked and retried repeatedly until the condition passes or a timeout period expires.
e.g.
Wait Until Keyword Succeeds 1 min 1 sec Element Should Be Visible xpath=//input[#id='aName']

Try using Wait Until Element Is Clickable as it is a button, it should solve your issue.
so, it should be something like
Wait Until Element Is Clickable deleteItem timeout=10

Related

Robot framework: How can I make sure that before running "click element" keyword, robot framework waits until the element is actually clickable?

I use "wait until element is visible" keyword before every "click element" keyword.
But now our web application is working slower and basically all of my tests fail.
I keep getting error messages like the followings, all because the page is still loading, the navigation has not been finished,
and robot does not wait:
"StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: headless chrome=102.0.5005.61)"
"ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (1385, 376). Other element would receive the click: ..."
(Unfortunately, robot documentation does not mention here that "visible" does not mean that the element really is visible and clickable....)
I can not put in sleep times before every "click element" keyword. I can not handle random loading times with explicit waits.
It is such an obvious problem and I'm surprised I could not find a simple solution for it yet....
So how can I make sure that before running "click element" keyword, robot framework waits until the element is actually clickable?

"Run keyword if"- want to perform double click on a button with this Built in function

So, in brief, i have to perform click on one button and validate for one of the panels whether it is visible or not. So problem starts from here. sometimes it is visible after 2 clicks, and sometimes 1 as per some prerequisite(this is not a bug). Now i start with the solution like if the specified element is not visible then again click on that button and (2nd condition--)if it is visible then go with simple logic as it is.
Run Keyword If Element Should Not Be Visible xpath=//div[#id='menu-container'] Click Button css=[ng-click="toggleMode()"]
I am using Run keyword if-Built in function, Could anyone give me heads up how i can tackle this.
You can first check if the element is not visible and click, only if the status is True.
${status}= Run Keyword And Return Status Element Should Not Be Visible xpath=//div[#id='menu-container']
Run Keyword If '${status}'=='True' Click Button css=[ng-click="toggleMode()"]

Robot Framework: Is there general setting for the Wait Until Element Is Visible

In the Robot Framework it is good to check that the element is loaded in the page with the
Wait Until Element Is Visible
keyword before using the element. I have implemented my own keywords:
Push
[Arguments] ${element}
Wait Until Element Is Visible ${element} 10
Click Element ${element}
Insert
[Arguments] ${elementti} ${text}
Wait Until Element Is Visible ${elementti} 10
Input Text ${elementti} ${text}
I'm using these keywords like this:
Push elementId
Insert elementId text
Is there general setting so I don't need my own keywords? There is general variable ${DELAY}, but (according to the documentation) with it all executed commands are delayed and the test takes too much time.
BR,
Sakke
As described in the documentation, you can set an implicit wait.
You can specify this when you load the library (by setting the implicit_wait option), or through the keyword Set selenium implicit wait).
However, this won't cause the application to wait for an element to be visible. It causes selenium commands to wait until an element is available in the DOM.

Click Button in ExtendedSelenium2Library selects button very slow

I am using 'Click Button' from ExtendedSelenium2Library to select Login button on my login page.
But is takes more than 12 seconds to select the Button. With Selenium2library it works immediately.
I prefer using Extendedselenium2 instead of selenium2. How to make it click faster?
TL;DR
Click Button ${button} True
Seems you already figured this out, but I had the same problem and it took some time to figure it out. So this is for future reference.
ExtendedSelenium2Library waits for AngularJs to be ready to process the next request. As can be seen here ExtendedSelenium2Library (and like you already said). So by using these commands that wait for Angular to be ready, when you are not using AngularJS, it is necessary for the timeout to kick in which is about the 12-14 seconds you experienced. To still be able to use the extended library and have "fast clicking" you need to set the argument "skip ready" to "True".
Example:
Click Element xpath=//a[#href="#/motor"]
Becomes
Click Element xpath=//a[#href="#/motor"] True

Selenium record and play back a css element

When i try to playback a recorded script, in which there is a click on css drop down like thing and select an option from it, i got the following error:
"Element not found".
Here there is nothing like loading so that it takes some time and element is not visible. It's just a plain web page.
Please help me in resolving this issue and go on with the recorded script.
Try invoking a mouseOver command on the underlying element, that should give the dropdown menu a hint to appear and the element you're missing will be visible.

Resources