Can I use Selenium IDE and have it use XPath instead of ID by default? - selenium

I have a situation where the IDs of all elements are unique GUIDs, regenerated on each page load.
So I can't use IDs, although Selenium IDE defaults to IDs for obvious reasons.
My workaround is to record with Selenium IDE, then go back and manually edit the IDs to replace them with the right XPath, but this is really time-consuming.
Is there a way it can be set to use XPaths instead of IDs, by default?
Or is there another similar application/extension which can do this?

Selenium IDE/Katalon... recordings can be an OK starting point, depending on who you ask, but you need to go over them.
XPath expressions are specially tricky and often need to be worked on after a recording tool obtains them.
There is no way around this even if you can get the tool you are using to use xpath by default somehow.

Related

In chrome dev tools what is the combination of these attributes called and why can i not just do a quick copy of them

I don't see anything in the right-click menu that will give me this. I always have to write it manually
Are you asking about button#checkout.button-1.checkout-button? If so, I'm not aware of a way to copy-paste this, or a name for it, but it is constructed with the format
htmlTag#idOfElement.class.with.periods.instead.of.spaces
It is pretty commonly a unique selector for the element in question.

Selenium Unable to locate element from class

I am trying to get 'Administrator' value from my website and this is the element
<td align="center" class="okm-DisableSelect">Administrator</td>
I copied the xpath using chrome and I got this value
/html/body/div[5]/div[3]/div/div[6]/div/div[4]/div/div[2]/table/tbody/tr[3]/td/div/div/div[2]/table/tbody/tr[3]/td[7]
I tried this but it gives me error 'Unable to locate element'. What am I doing wrong?
driver.findElement(By.xpath("/html/body/div[5]/div[3]/div/div[6]/div/div[4]/div/div[2]/table/tbody/tr[3]/td/div/div/div[2]/table/tbody/tr[3]/td[7]")).getText();
First off, that XPath is massive which is going to make it very brittle (likely to break). You shouldn't use an XPath that starts at /html and you shouldn't really use an XPath that is more than just a few levels deep... maybe 3-5.
Secondly, you haven't given us enough info to see what's wrong with that XPath because it is so huge. Your best bet is to NOT use copy XPath because it generally leads to large, brittle XPaths like this. Ideally you would use CSS selectors instead of XPaths because they are better supported, faster, and easier to craft. You should spend the time to learn how to handcraft them instead of using some tool because they will be shorter and less brittle, if done right.
Given the HTML provided, I would start with a CSS selector like td.okm-DisableSelect and see if that works. If it does not, you could fall back to an XPath using the contained text, "Administrator", e.g. //td[.='Administrator']. There are, I"m sure, many more options but without more HTML I can't tell you what they would be.

Selenium IDE: pick up a database value

I made a test case with Selenium IDE that makes 25 addresses using a while-loop; starting with housenumber 1.
What I actually would like is that the maximum housenumber is picked up from the database, so we can reuse this case endlessly.
In SQL: select max(housenumber) from tbl_address where streetname = ‘Testingstreet’;
Is this possible, and if so… how?.
(As Slanec pointed out, the comments should probably be an answer).
This is way outside the scope of the IDE. You have reached a point where the IDE is not capable of doing what you want your tests to do, therefore you will either have to workaround this issue somehow, or (better IMO), scrap the IDE altogether and use WebDriver & a programming language directly.
I would use the IDE to export your current tests into whatever language you want, then use the language to find out some library or API that allows you to connect to the database.
Usually, keeping to the same programming language and database libraries as your application under test uses, is a good idea.
One way around the limitations in IDE is to create an internal webpage that you can pass queries through to your db and return the response as a table. Interacting through that page would get you the data you need.
Like the answers before me, I suggest going with the WebDriver, but if you MUST use IDE this could be a solution for you!

Capturing variable xpath in selenium IDE

Am trying to capture a element (delete button in gmail) which has variable xpath.
The xpath is something like this-
//*[#id=':rr']/div/div[4]/div[1]/div[1]/div[1]/div/div/div[2]/div[3]
can somebody kindly help?
No, this is where the IDE falls behind and it's for good reason. It, along with other 'XPath-ified' (e.g using the 'XPath' right-click option in Firebug) tools will only take a guess at where something is located in the DOM.
In that, I mean it's going to walk down the tree and see where it is, in relation to the other elements, i.e it'll walk down one set of tr elements, and know there are 7 of them, therefore it'll know that the first one can be accessed using [1], then the next one can be accessed using [2] etc etc...
It doesn't, or really can't, know what is unique enough for you to use. That's why it's down to you to figure it out.
As for Gmail specifically, I would suggest you either fall back to Gmail's basic mode - so the markup will be easier to deal with or stop completely and use a particular set of API's in whatever language you are using to deal direct with the mailboxes in that account.
Though, if you do this, you'll need to dump the IDE altogether - essentially this is beyond the IDE and is a logical thing you need to decide yourself. The IDE is not designed for this.
Though, a tip would be see what's near the delete button. Is there a static element, that has the same attributes all the time, near it? You can get that element, and walk through to the DOM to your 'delete button'.

Looking for a Jubula hack / alternative which makes identifying components using XPATH possible

We have plans to use Jubula to test the functionality of our web application but after evaluating Jubula we have run into a problem. We can't make Jubula click fields which have a varying id (generated).
I know that Jubula uses Selenium inside so using XPATH for maching elements in the DOM should not be a problem. Do you know about any Jubula hack or alternative / derivative which makes this possible?
I think it is not that easy to use XPATH directly with Jubula. However, Jubula uses XPATH internally to address components in a web page.
Your problem might be solvable by just ignoring the id's and using context and hierarchy for component mapping. To do this just try setting the names weight to zero in the object mapping editor (on the Configuration View). You may have to adjust the Threshold slider as well.