How do I choose the locator for the dropdown list in selenium IDE - selenium

this is the code where the value d3395be8-doctype changes everytime the page reload. I am really having trouble automating this scenario.
<select id="d3395be8-doctype" style="height:24px;width:100%;" name="d3395be8-doctype" changeevent="true
this is the command i use. it always return errors:
XPath: //*[ends-with(#id, 'doctype')]

Your issue could be because the ends-with function is part of xpath 2.0 but your browser might only support 1.0. As a test you can try //*contains(#id, '-doctype') If that works, then it's highly probably that this is your issue. If you want to get more precise with the locator you can roll your own version of ends-with using the string-length and substring functions.

Related

How to identify an element without using xpath when id name is not available in selenium

There are few elements in an UI page without ID. I will download a particular version and then save all the current element tags and give to script as input, since few elements are not having id, this is causing script failures.
How can I locate the element without using Xpath.
Is there any simple way when there is no fixed id.
The short answer is "no." Sorry. All of the usual ways (by id, class, etc.) are relying on the same css information to locate elements. Xpath just shows all the ugly plumbing out in public. I don't think xpath has ever been described as "simple" but there is usually a way, using xpath, to find any element.
Xpath can be intimidating. Start with a plugin that will generate the xpath for you, once you click on an element. Usually the xpath generated will be extremely long and inefficient, but with practice you can see what can be trimmed and what is crucial. And to do that, also use a plugin that will "check" your xpath to see if it can find the element. Once you can find it (and ONLY the element you want) try trimming it to see if you can still find it with the abbreviated xpath locator.
reference ImageDon't be afraid of Xpaths. It's relatively easy to grab an Xpath using the Google Chrome browser. Navigate to your page and open Developer tools. Right-click on the particular tag for which you need an Xpath. Copy -> Xpath

nightwatch xpath selector not working

I'm currently working on a node/express.js app for which I'm writing some e2e tests in nightwatch. Today I hit a roadblock while trying to search for an element using the XPath locator strategy. Basically I can search for elements using any of the following:
//div[#data-pino-name='userIdSection']
//input[#name="password"]
//input[#name="username"]
//button[#data-pino-name="submit"]
//a[#data-pino-name="cancel"]
By the way, all of the selectors above work fine using the chrome tools.
However, using the following:
//pre[#data-pino-name="requiredErrorMessage"]
doesn't work at all. I'm surprised since I expected the <pre> tag to be treated the same as any other html tag. However, the test returns a "element was not found" for all elements with the pre tag.
Anyone guidance would be appreciated.
You can follow this approach in writing XPath based on your scenario
//div[#data-pino-name='userIdSection']/pre
//div[#data-pino-name='userIdSection']/pre[#data-pino-name="requiredErrorMessage"]

Finding clickon Element using Selenium. (JAVA)

I spend hours already trying to find the way to find the Element using Selenium WebDriver. I assume I need to use driver.findElement(By.xpath("")), but I am not quite sure how.
I somehow need to find and click on "clickon" element. The problem is that part of that element is changing (see screenshot) I need to pick up from the file and putted into the xpath.
I would appreciate any help.
We have been rigorously searching for automated functional testing solutions recently, and we began with Selenium. The entire reason we decided to search for other solutions was that our application also has dynamic IDs with no other obvious XPath mechanism to identify them. Selenium is unable to identify these elements on the page without some additional knowledge, just as you would be unable to identify these elements on the page if you didn't already know what they are.
If you are controlling the DOM creation, consider adding a unique ID or class to this element.
We recently came across eggPlant from testPlant, and it is an interesting approach to functional testing. It's essentially image based. Other viable solutions are Ranorex or HP's QTP or SmartBear's TestComplete.
You can use xpath. If the div class is constant, you can use something like:
driver.findElement(By.xpath("list-row field-item")).click();
To view the xpath, you can install firefox plugin called 'xpath checker' found here and right click on the dom element and click 'View Xpath' option to get the xpath of the element and then you can use that xpath in your code.
Or you can even use regex in the xpath which is suitable for the similar problems. Xpath with regex is really powerful.
It seems that you want to click the div that has the on click attribute that contains certain text that doesn't change, ignoring the part that does. In that case, use an xpath like this:
//div[contains(#onclick, '/challenge/index/rfp_id/')]
This will select the first div with an onclick attribute with a value containing /challenge/index/rfp_id.

Selenium use a Tree class for expanding/clicking a node in a tree made with RichFaces

In Selenium RC I need to expand/click a node in a tree made with RichFaces. I have done a TreeUtil class, but at this point I am not sure how to click/expand a node (which I retrieve with this xpath: "//div[#id='foo:classTree']/div/div/table["+nodeLevel+"]/tbody/tr/td/div/a") using only a nodeNumber and a nodeLevel.
Anybody has any idea?
Your question isn't very clear to me: are those click commands (with the XPath) not working because they result in "element not found" errors or because the click simply isn't causing the behavior your expect?
If it's an element-not-found issue, I suggest you use Firebug's $x function in the console to refine your XPath. You can run this function call in the Firebug function to see what the XPath is truly evaluating to:
$x("//div[#id=\"foo:classTree\"]/div/div/table[XXX]/tbody/tr/td/a")
Where XXX is some index. This is by far the best way to figure out the right XPath.
If the problem is that the click is just not really causing the tree map to change, try switching from click() to fireEvent("//xpath", "click") and see if that helps.
In my case clickAt() helped.

Selenium xpath flow

Can anyone tell me what is the exact flow of taking out xpath in Selenium-IDE.
After trying alot by putting alerts i m not getting how to take out the exact xpath.
Selenium displays the xpath according to xpath:position and some others ways also but i want to add the xpath traversing from html i.e the topmost position.How can i do that???
I've come to prefer CSS selectors over Xpath. The IDE won't create them for you, but with a little practice they're very easy to write. As a bonus, they make your tests much easier to maintain.
For example, let's say you have a button with the text "save". The locator would be:
css=button:contains('save')
Check out http://www.w3.org/TR/css3-selectors/ for more detail.
I use XPather to find out the xpath. Then I use the resulting path in the Selenium IDE to cross verify. You could also use other tools like XPath Checker or Firebug to do the same.
Write 1 line of code in javascript:
LocatorBuilders.order = ['id', 'link', 'name', 'dom:name', 'xpath:link', 'xpath:img','xpath:attributes', 'xpath:href', 'dom:index', 'xpath:position'];
change it the way you want (not all of them has to be there)
see:
chrome://selenium-ide/content/locatorBuilders.js
save as your_file.js
add your_file.js as "Selenium Core extensions" in the IDE options
Firefinder for Firebug helps matching both CSS and XPath locators
In general, with Firebug installed, you can Inspect Elements for their HTML and DOM structures to determine what best locator you can build.
the best way to find x PAth is :
open developer tool bar in chrome:
Find the x Path displayed below :
You can directly copy and paste this x path in your script