Click Element is not working in Robot Framework, in the log.html it shows that it clicked on element, but it does not actually happen on the browser
This application is not an Angular JS application.
I have tried the same functionality in other application which is an Angular JS, it worked fine.
My Robot code is as below:
*** Settings ***
Library Selenium2Library
*** TestCases ***
Login to Application
Open Browser ${url} ff
Maximize Browser Window
Select from List by value id=selectedCountry MU
Input Text id=userid rajaint
Input Password id=password rajaint1
Click Element id=Submit1
what can be the reason for this?
I'm stuck in automation, as I stopped at the login.
I cannot share the application url as it is confidential.
After having a chat with Sarada - We discovered that the issue was on his application. The problem was the application had to lose focus of the drop down menu and the username field in order for the validation to pass through - and allowing more input from robot.
After some trail and error, we figured out how to lose focus of an element and allow the validation to work as intended; which in return meant everything else worked smoothly!
I suggested Focus but that did not work so instead we forced it using:
Press Key id=userid \\9
Which sends a Tab to the browser. Making it lose focus and making the validation tick over!
In the end the Robot File looks like:
Open Browser ${url} ff
Maximize Browser Window
Wait Until Element Is Visible id=selectedCountry 10s
Click Element id=selectedCountry
Select from List by value id=selectedCountry MU
Click Element id=selectedCountry
sleep 2s
Focus id=userid
Click Element id=userid
Input Text id=userid rajaint
Press Key id=userid \\9
sleep 5s
Input Password id=password rajaint1
sleep 2s
Click Button id=Submit1
sleep 10s
Capture Page Screenshot
I have experienced the same problem but the Press Key Trick is not working.
I used this hack instead
Execute JavaScript
document.getElementById('Submit1').click()
And it's working fine
Similar problem was faced by me.
The JavaScript worked perfectly.
Execute Javascript document.querySelector('#HIRESearchTable > tbody > tr > td.searchLink > span').click();
For this kind of scenarios, you can use JavaScript Executor. But in most of these cases, you can't find the Id of the element. So I have implemented a common keyword which can be used with the xpath.
Click Element By JavaScript Executor [Arguments] ${elementXpathLocator} ${retryScale}
[Documentation]
... Click an element by xpath using javascript executor ...
Wait Until Keyword Succeeds 2x 1 s Wait Until Element Is Enabled ${elementXpathLocator}
Execute JavaScript document.evaluate("${elementXpathLocator}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).click();
Sleep 1s after you found the element. It works for me.
Related
I try to capture alert screenshot but in the screen doesn't show alert box.
For Example:
AlertTest
Open Browser http://www.seleniummaster.com/robotframeworktest/alerttest.html ff
Sleep 5s
Click Button name=alert_button
sleep 10s
capture page screenshot
Alert Should Be Present This is an alert box
Close Browser
If anyone has experience could you help me please.
To my understanding it is not possible to capture the alert with SeleniumLibrary, because the alert in not a part of the page.
We walk around this by using the BuiltIn Screenshot library and the KW Take Screenshot.
You could try and consider if it meet your requirements.
The behavior you're seeing is due to the Alert should be present keyword automatically accepts the alert. It happens so fast that if often looks that it never happened. By adding the optional parameter action=LEAVE you can check without modifying the behavior. The Keyword documentation shows other options.
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
AlertTest
Open Browser http://www.seleniummaster.com/robotframeworktest/alerttest.html chrome
Sleep 2s
Click Button name=alert_button
Alert Should Be Present action=LEAVE text=This is an alert box
Handle Alert action=ACCEPT
Close Browser
Although this will solve your: I don't see the Alert part of the problem, you will run into the next one. Taking a screenshot using SeleniumLibrary will not work because of the now present Alert. As suggested earlier, this can be taken care of by the Screenshot Library keyword Take Screenshot .
Please read the Using with Python section carefully as this library depends on Operating System specific Python modules.
When Click on the Declare Failure Link, using Click Link Code:
span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']
the Error is Displaying as
Link with locator
'//span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']' not
found.
Robot framework
Click link can only be used to click on link (e.g. an <a> element). If you need to click on a <span>, use Click Element.
Since the Click link keyword can break for other elements, I use the most generic way which is Click Element.
*** Setting ***
Library SeleniumLibrary
*** Test Cases ***
Example
Open Browser ${url} ${browser}
Click Element id:ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9
Instead of Id, you may also use the xpath. In this case you will have:
Click Element xpath:.//span[#id='ContentPlaceHolder1_grdFailureDetails_lblDtcCode_9']
For more information, refer to https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html
Unable to enter text in input box using robot framework because of the error "InvalidElementStateException: Message: invalid element state: Element must be user-editable in order to clear it."
Open Browser https://outlook.live.com/owa/ chrome
Maximize Browser Window
sleep 5
Click Element Xpath=/html/body/section/div/div[2]/div[2]/div/div
Input Text Xpath=//[#id="i0281"]/div[1]/div/div[1]/div[2]/div/div/div[2]/div[2]/div/div[2]/div testing.sample#outlook.com
how to fix this issue???
python2.7 version
selenium 3.6.0
Here, ID field is changing, so using absolute xpath will resolve this issue, here is my working code ...
*** Settings ***
Library Selenium2Library
*** Test Cases ***
RnD - Test1
Open Browser https://outlook.live.com/owa/ chrome
Maximize Browser Window
Wait Until Element Is Visible Xpath=/html/body/section/div/div[2]/div[2]/div/div 10
Click Element Xpath=/html/body/section/div/div[2]/div[2]/div/div
Wait Until Element Is Visible xpath=//body/div[1]/form[1]/div[1]/div/div[1]/div[2]/div/div/div[2]/div[2]/div/input[1]
Input Text //body/div[1]/form[1]/div[1]/div/div[1]/div[2]/div/div/div[2]/div[2]/div/input[1] testing.sample#outlook.com
I'm a backpacker and a programmer, trying to use the second skill to find openings in a full campsite. Rather than crawling fro scratch, I'm using the end-to-end testing framework nightwatch.js to navigate for me.
I've hit a roadblock, because nightwatch is having difficulty finding a specific element using css selectors.
Here are the elements and page:
Here is my test code:
Previous Attempts
My test code will click on the selection box with #permitTypeId. It will see that #permitTypeId option is visible. It will not see or click on any of the options when more specific values are specified. The five .click()'s are all css selectors I've already tried. None of the options are set to display:hidden or display:none. I have also tried all of the above without the .waitForElementToBeVisible() just in-case the waiting causes the dropdown to hide.
I've successfully clicked options from different dropdown menus on this website without any problem. Just this one is causing a headache.
The tests are running with the most current Selenium server and Firefox on Mac Yosemite.
tl;dr
Nightwatch.js/Selenium won't click on something from a dropdown menu.
The Path...
Cory got me thinking about jQuery and native DOM manipulation. Tried going that route and was successful selecting the correct option using Selenium's .execute() function:
.execute('document.getElementById("permitTypeId").options[1].selected=true')
However, it was not triggering the onchange event.
Saw this post which made me start thinking about using key-strokes and this one which suggested using arrow-keys to navigate down a <select> element to the option, then hitting enter.
...to the Solution
.click('select[id=permitTypeId]')
.keys(['\uE015', '\uE006'])
I've found that this is an issue with Firefox. Chrome and PhantomJS operate well clicking <option> tags.
you should be able to click like this way
browser.click('select[id="permitTypeId"] option[value="1451140610"]')
Additionally I was able to add a .click event for the specific option once I did a .click for the select. see my example below:
.click('select[name="timezone"]')
.pause(1000)
.click('option[value="America/Chicago"]') //selects the option but doesn't click
.pause(5000)
.keys(['\uE006']) //hits the enter key.
another solution:
.click('select[id="permitTypeId"]')
.waitForElementVisible("option[value='1451140610']")
.click("option[value='1451140610']")
Very simple way is to use .setValue('#element', 'value of option')
I have a small requirement..
if the user dint sign off or log off then he try's to close the browser IE clicking on 'X' (top right of IE or Firefox browser ) then i need to ask a conformation message like "Are you sure you want to close ?" ...
I am using Master page in my application and i tried the event : "window.onbeforeunload " in my master page its works fine, shows an alert(conformation) message. but if i press back button on the browser(IE on IE or Firefox) then also its firing(but it should not) is there any way to full fill my requirement ..I hope i had explained u clearly...if not pl z let me know........
what i mean to say is.. if the Session("USerid") is active or if it contains any value ie.
Session("USerid")="XXX"
at that moment if user trys to close the browse(click in 'X'/Close button browser either IE or Firefox ) it should give prompt a message "are u sure do u want to close?"..
Its all about design steps - but the close and the back button is the same, the close the page, so maybe its impossible to have them all together.
To open, close your script you can make a simple trick. Place them inside a literal and open or close it.
<asp:literal run="server" id="txtCloseAlert">
<script>
... you code here ....
</script>
</asp:literal>
and on code behind.
txtCloseAlert.visible = !string.IsNullOrEmpty(Session("USerid"));
I've looked into this recently and there does not appear to be a standard / consistent way to do this cross-browser hence you back-button problem.
On IE at least you get an event object passed as a parameter to the onbeforeunload method that you can use to get the mouse position, but in FireFox you don't and you would need some other way to determine whether a confirmation is required. It is quite posible that you could get the mouse position in some other way as I haven't looked into that. Point is that if your mouse is not on your form you probably want a confirmation.
You can look at this SO question:
Prevent browser from closing in asp.net
Or do an Internet search on 'onbeforeunload prevent browser closing'.
In your case a synchronous ajax call can be made to the server to do the test.
HTH