Hi,
I have a button which is embedded inside a class “form-group.pull-right”. So form-group.pull right class has to be selected first and then I need to click on the button. You can assume it as a frame which needs to be selected first… I ran selenium ide and recorded my click and it translated into “Select Frame index=0”. But when I use the same in robot framework it cribs because according to robotframework syntax you can select a frame either by id or name. In my case “class form-group.pull-right” neither has name or id. I experimented a lot but not able to figure out how I can select the outer frame form-group.pull-right and then the button. Any guidance how to do it will be really helpful. Attaching a screen shot also…
Hi @rkamala ,
Are you getting an error when you try to click the button directly? probably saying that the button couldn’t be clicked because the div would receive the click?
The html you showed for class form-group.pull-right wasn’t a frame or iframe, so there would be no reason to select it first and then click the button, I expect you simply need to just click the div that the button is inside. If that’s the case a simple xpath like //button[@id="createSipBtn"]/..
might be all you need. (remember click element not click button)
Dave.
Hi,
Thank a lot for your reply. When I click the button directly it is not giving me error. I used this "
Click Element xpath = //[@id=“createSipBtn”] in the robot framework… It is giving me the error "Element with locator 'xpath = //[@id=“createSipBtn”]’ not found.". xpath is correct.
I tried few other things also
Click link xpath = //a[contains(text(),‘Create SIP’)]
sleep 5
Click Element xpath = //a[contains(text(),‘Create SIP’)]
sleep 5
Click Element xpath = //*[@id=“createSipBtn”]
sleep 7
This is also not working
I feel since it is under frame it is giving me the issue… I ran the selenium IDE also to capture the commands… It first selects frame with index=0, but when I examine it it is not under frame. And I am not sure how do we use frame with an index in robotframework… It does not have neither id or frame.
Any tips will be really helpful since I am stuck in this issue for long time
That’s not a valid xpath, you need something between the double slash (//
) and the open square bracket ([
)
this should work though if you comment out the lines before it (one line fails and the rest get skipped usually)
As you already had dev tools open on the elements tab, FYI you can click a html element and press ctrl-f (find) and then test your xpaths directly in devtools so you know they’re good before you put them into your robot file.
I can’t see enough of your html to know if you are within a frame or not, if you switch to the console tab of devtools there is a dropdown in the first line of the toolbar (probably says top with a down arrow), that dropdown will show you if there are any frames, if there are you’ll need to work out which frame your element is in. then use Select Frame to select it. be careful of nested frames, as you’ll need to walk the script down the frame tree with Select Frame several times.
Dave.
Hi Dave,
Sorry troubling you again… I think this particular element “//*[@id=“createSipBtn”]” it is under a DOM node… Enclosing some screen shots if you get some idea as to how do I access this particular element… Your help is really appreciated… Thanks once again…
Regards-Kamala
Hi Kamala,
That screen shot shows a few things:
- that xpath is correct, it found your element
- you do have at least 1 iframe, but you will need to check if there are more
- it looks like the iframe I can see doesn’t have an id, so you might be best to identify it by it’s parent div
Something like this might work, but as I said if there are other frames/iframes you’ll need to work your way down to tree till you get to the frame that contains the element.
Select Frame //div[@id="reportDiv"]/iframe
Click Element //*[@id=“createSipBtn”]
Dave.
Thanks a lot Dave… I shall try and let you know the outcome…
Regards-kamala
Hi Dave,
My heartfelt thanks.. It worked. So happy.. I just have few follow up questions which might be basic. Please don't mind..
-
If an iframe does not have an id as in our case how were you able to find id as "
//div[@id=“reportDiv”]/iframe" -
If there are more than one iframe where can I check… In my case "under style I saw that there is one iframe existing. Is this the right place to see… Enclosing the screen shot also.
-
I have few xpath’s which look like this… I need to use mozilla firefox…
a) Click Element xpath = /html/body/div/div[2]/div[1]/div/ul/li[2]/ul/li[2]/a
b) Input Text
xpath = /html/body/div[1]/fieldset/div/create-sip-element/form/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/div/input ${service_name}
For question 3, I have certain clarifications:
3(1) — I don’t get a valid xpath in many cases and I am forced to use in the above format. But I read somewhere these kind of xpath’s are subjected to change… Can you please suggest me for these kind of cases where I get such xpath’s what is the best way to code.
Thank you once again for all your help… Enclosing the screen shot where I get to know one iframe is present…
Regards-Kamala
Hi Kamala,
-
from your screen shot in this post I extracted this section below: You can see the iframe (highlighted in green) doesn’t have an id, however the iframe’s parent, a div (highlighted in orange) did have an id (the part after the #) so the xpath I gace you for selecting the iframe used the id of the parent and then selected the iframe that was an immediate child of that div.
-
Yes you are correct if there was more than 1 iframe in that parent div then you would a more specific xpath, that could be as simple as adding
[1]
to specify the first iframe, or using another attribute of the iframe, unfortunately there wasn’t enough information in your screenshot to give me that information. -
w3schools has a really good XPath Tutorial for learning how to construct good xpaths, work your way through that tutorial and take your time to really understand it, the time invested in learning how to contruct good xpaths will save you many times over the time you invested.
The tips I’ll give you are:
3.1 try to keep your xpath as short as possible while still uniquely identifying the element you want to target.
3.2 look carefully at all the attributes of the element you want to target, anything that can be used to uniquely identify the element is the attribute you should use, sometimes it’s the text within the element is the most unique item in which case use the text() function, some times it’s a class but if there are many classes and you only want to target one, use the contains() function.
Also JSONpath is very similar to xpath, so the time you spend learning xpath will help with understanding JSONpath later down the track.
Dave.
Thank you so much Dave for answering in detail my queries… Really appreciate that… For sure I will go through the xpath tutorial you pointed to… But I might still bug you if I hit any other road blocks… Hope you will not mind… Thanks a lot once again for being so helpful. I am not sure how can I repay it back…
Regards-Kamala
Hi Kamala,
I’m happy to help people, don’t try to repay me, pay it forward and help someone else when you can.
Dave.
Sure Dave… I shall do so… The xpath link you shared is quite good and precise… Thanks…
Hi Dave,
I just hit another issue while automating using rogers framework. I have a radiobutton whose xpath keeps changing say today it shows xpath as RadioButton131 and after few days it changes to RadioButton132 etc. I tried to code in another way saying if you find this text then click on that link. But that seems to not work. Please let me know what is the good way to handle it. Enclosing the screen shot also.
Click Button xpath = //*[@id=“customerRadioButton131”]
Regards-Geetha
Hi Geetha (or Kamala?)
There’s a couple you could handle that
- A simple option is to just use the name if you can rely on it:
//*[@name=“selectedElementId”)]
- if the radio button you want will always be the only one on the page you can simply use contains on the id:
//*[contains(@id, “customerRadioButton”)]
- a small variation on this if you always want the first one (incase there are more:
(//*[contains(@id, “customerRadioButton”)])[1]
- another option is to use the value in the next cell as a reference point something like this:
//tr[td[text()="SOW_134"]]//input[@type="radio"]
There are probably other was as well, it really depends on your application and how it behaves as to what’s the best or most reliable option.
Dave.
Thanks a lot Dave for such a quick reply. I shall most probably go with the third or fourth option and let you know the results.
Regards
Kamala(Maiden name)
Actually all the options of yours worked. But I went for the option 3. Thanks a lot for giving me different ways of handling such issues. I have few more clarifications on how do we validate a value set by our script. I might ping you for that if my tries don’t fetch me results. Thank you once again.
Regards-Kamala
Hi Kamala,
Glad I was able to help, post any questions you have on this forum and someone will help, don’t wait for my help, others hopefully will.
I’m not sure when i’ll be able to be back, as I’m currently in hospital (since Tuesday) and not sure what my recovery time looks like yet, the doctors have given me a positive recovery plan and hope to have back to 100% in the next few weeks, I won’t be online, I lots of physiotherapy to do for my recovery.
Best of luck learning Robot Framework.
Dave.
Please take care Dave. I pray God for your speedy recovery. Don’t worry about my doubts. I shall post it in the forum. But I shall surely wait for you to come back in action again. Please take complete rest and good care of yourself.
Regards
Geetha