New answers tagged


This is a common issue where sometimes creating locators become so confusing and cumbersome that we end up taking help of some automation browser extensions. Working in a professional software testing company, I have used many such extensions which have made the daily automation tasks very smooth. Below are few - Selenium IDE Recorder - One of the best ...


The simplest solution would probably be something along the lines of function extractInner(selector){ let elements = document.querySelectorAll(selector); let toReturn = []; elements.forEach(x=>{ toReturn.push(x.innerHTML); }); return toReturn; } extractInner("a.username"); this returns you a list of string ...


What you get in the console (a.username) is the CSS selector, if you are using xpath you will need a[@class='username']. Try something like this $x("//a[@class='username']")[0].innerText The $x("//a[@class='username']") will return a list of zero-indexed elements. So [0] will select the first element of that list and so on.


As mentioned in previous answer using custom loctors or tools to find xpath is not a recommended approach. Learn the xpath functions and appraoches. You can always use parent elemeent to refer a child element uniquely or combine different attributes together. in your case you can use : //*[contains(text(),"Paper") and @class="a-size-small a-...


Automated xpath generators can help sometimes, but will generally be very unstable and you could do better by creating the xpath yourself. Try to find an unique element (maybe one with an 'id' value) as the parent of the element you are trying to reach and then construct your own xpath. Maybe this cheatsheet can help.

Top 50 recent answers are included