selenium doesn't run when web page is loading - selenium

I am running some tests where I have to restart a server by clicking a "restart" button. There is a small text being displayed near to it which will show the status of the server.
Before clicking the "restart" button, the text shows "running" and after clicking it, the whole web page keeps loading and the text shows "restarting". After the page stops loading, the server successfully starts running again and the text shows "running".
I have to write a test case which checks if the text shows "restarting" when the "restart" button is clicked. But unfortunately I am not able to find a way to make the selenium check if the text is showing "restarting" as it is unable to do anything since the webpage is loading at that time.
Can anyone help me out by showing me a way how to make selenium run when the webpage is loading? I am not getting good replies in google search about this. It will be great if someone can help me out.
Thanks

Usually you can drive a browser even the webpage is still loading.
I would suggest to find the element for "restarting" and keeps checking it until 60 secs
In ruby, you do something like
wait = Selenium::WebDriver::Wait.new(:timeout => X)
wait.until {driver.find_element(:id => 'restart_word')}
where X is the number of seconds to wait.
After X seconds, it will timeout.

Related

Robot Framework Selenium Library - Don't wait for result from submitting form

I'm new to using Robot Framework/Selenium Library.
I'm trying to create a test that enters values into form fields and submits the form by clicking a button.
I only want to check if an alert is present immediately after submitting the form, then close the browser and end the test but at the moment the test is waiting the 2-3 minutes it takes for my script to finish running and the new page to be loaded.
Is there a way I can tell Selenium not to wait for the result and check for the alert immediately then close the browser after verifying if the alert is present or not? The flow of the test currently is:
Test Alert Present
Open Browser And Maximize
Select From List By Value id=mySelect myValue
Click Button id=runScript << waits 2-3 minutes here
Alert Should Be Present
Close Browser
Thanks
Edit:
This seems to be a problem specifically when running tests with Google Chrome.
When running with Firefox, Selenium seems to wait 5 seconds before continuing with the next test instructions.
First, get the values to understand if selenium is waiting or anything else:
Get Selenium Speed
Get Selenium Implicit Wait
Log them to console then we can decide next steps.

Seleniumlibrary command not working with Ride?

The issue I'm having is with the command Go Back from the selenium library within RIDE.
I have tried to input the Go Back command into a test script im running. The website should then simulate a click on the back button within the browser (chrome). It however does not seem to work while it does tick off the step as done and passed. I googled some stuff and found out sometimes the browser isnt ready loading when trying to perform the next command and thus it could create an issue. Because of this i tried to implement the Set Selenium Implicit Wait 10 seconds command
In the img link below (can't post the img because im not 10 reputation) you can see that I have the command Go Back and Set Selenium Implicit Wait 10 seconds. Neither however seem to work (notice that while the timer is suppose to wiat 10 seconds. it is marked as completed in 00:00:00.003
https://gyazo.com/fa18566997436989ab5a6503b9064965
I noticed that both come from the seleniumlibrary and while installed and imported (or Close Browser would not work) neither works. I'm not sure what im doing wrong here. In the picture below is how i wrote it down in the testcase.
https://gyazo.com/7d914c7c74999177ae2dca4a02d4a4bb
Any help would be much appreciated into making the bowser use the back button and/or explaining why certain aspects of the seleniumlibrary don't seem to work.
See the implicit wait section. It can be read like "the maximum time when waiting to find the element". When you use the Go Back keyword, there is no element to wait for, so it is immediate.
See here a complete example (that would work as long this question is on the first results page):
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Move Back On Browser
Open Browser https://stackoverflow.com/questions/tagged/robotframework%2bselenium?tab=Active Chrome
Scroll Element Into View xpath=//a[.='Seleniumlibrary command not working with Ride?']/../..//div[contains(#class, 'excerpt')] # Scroll to excerpt, because Cookie Policy ovelay is over URL element
Capture Page Screenshot active_questions.png
Click Link xpath=//a[.='Seleniumlibrary command not working with Ride?']
Capture Page Screenshot target_question.png
Set Selenium Implicit Wait 10 seconds
Go Back
Capture Page Screenshot after_go_back.png
[Teardown] Close Browser

How to handle dynamic error messages coming in an application

I am facing an issue while automating a web application at my work-place, and need helping advise to resolve the issue.
The application which I am testing is having a dynamic error popup screen which loads from the top whenever any error comes in the application. To be more clearer, let's say I am entering Username and password to login into application, and I took wrong username and password combination. Now, due to this a dynamic error drop down comes from the top. I am saying it dynamic because, as soon as I am trying to inspect the element, the error screen fades away. Now, due to this, I am not able to locate the element.
Sometimes, I got lucky and was able to inspect the element by right-clicking on that element. But then as soon as I reach to element tab, Error screen fades away, and not able to inspect the element.
So, I need help here to know how can I handle this dynamic error screen.
Any help will be appreciated. :-)
You can use devtools to pause:
1. Open app in chrome
2. Open devtools
3. Go to Sources tab
4. Trigger error and press F8 to pause
5. Go to Elements tab and locate error html
Two quick ways :
When you get lucky to reach until the elements tab after inspecting
the error, just copy the total div/span/error element's html code.
Paste it in a Notepad to locate the element with any strategy [like
xpath/css].
If the above could not help, then ask the dev to make the dynamic
error message to appear some more time and then you could locate
them correctly.

Unable to locate button element

I can see the enabled button while running. I can select that button using Selenium IDE and the xpath. But when it comes to running using WebDriver it is not able to find the element.
Are you using the localhost? because sometimes if it takes some extra seconds for the Web Browser to load (for example Firefox), then when Selenium tries to do the action it doesn't find the elements obviously resulting your error.
Use the pause command, for example 5 seconds, so that the Selenium waits 5 seconds before the action is executed, giving time for the website to load.
Try the coding somewhere on this level
driver.manage().timeOuts().implicitlyWait(5,TimeUnit.SECONDS);

Element link not found in Selenium

I am executing a simple recorded script in Selenium , in which i just search a page in Google and then click it , but when Run that recorded script it is giving me the "Error [error] Element link not found".
And following is the Script which i am running,any help would be very useful.
New Test
New Test
open
/
type
q
Bill Gates
click
link=Bill Gates: Chairman
click
link=Bill Gates: Chairman
I got the same error message while going through the tutorials online. I found out that the scripts were running too fast for FF to load the links. If you slow down the playback by moving the green button on the Fast-Slow bar to somewhere in the middle the scripts run without any errors.
I guess I know the answer. It might be bcz of any javascript error(you can see that on the status bar at the
Right corner(IE)) or that link element might not be placed correctly in the box(box model).
Here you can use
Selenium.focus("link=text")
:selenium.keyPressNative("10") . It presses the enter key.but while selenium is executing this statement
Do not change the focus from your AUT (don't touch the mouse).
In IDE ,just paste the above statement on click().
Well, I don't think you have to slow the speed down. You know the problem is caused by clicking on the link before it is available, so you could add an extra command waitForVisible (e.g. link=Bill Gates: Chairman) before the clickAndWait command.
Im assuming you are using Google instant as there is no "click search button" command, the link is probably not preset because selenium is not waiting for Google instant to respond or the javascript to render the link. If you manually add in a click command to search it should solve it.
My solution is almost the same as Cuongs. Though I change the speed by using a command and change it back afterwards.
Before you click the link, you can set the speed to slow:
Command: setSpeed
Target: 3000
You can change the speed afterwards again to ~1000
I also had same problem. I did two things which fixed the problem. I changed the speed in Selenium IDE from fast to slow (located at top left of IDE), and I minimized the IDE after hitting play button. I guess for people using only one monitor, minimizing Selenium IDE would help the test find the thing it is looking for; for ppl with two screens, opening Selenium IDE in one screen, and opening browser in another screen would be best.
Info: Installing this plug-in (Selenium IDE: Flow Control) fixed lots of unexpected errors for me while playing with Selenium IDE:-
https://addons.mozilla.org/en-US/firefox/addon/flow-control/?src=dp-dl-othersby