Using Selenium to click on an element which is in nested <div> <li> - selenium-rc

My page looks like the code given below in inspect element mode.
I have series of li tags inside div tags, whose ids are dynamically created while I load the page.
I need to click on Summary, intent, conversion elements.
Can anyone please help me how to do this in selenium RC.
The ids are dynamically generated so I cannot use the id option here. For example : the id yui_3_3_0_1_131676060142810944 is dynamically generated. Using xpath also, I could not click on these elements.
Please let me know if there is a way out. It would be very helpful for me.
The actual inspected source is here if it might help in looking into this.
http://paste.ubuntu.com/696262/

Here is the DOM tree with nested div
<div class="aui-helper-clearfix aui-tree-node-content aui-tree-data-content aui-tree-node- content aui-tree-node-selected aui-tree-expanded" id="aui_3_4_0_1_1005">
<div class="aui-tree-hitarea" id="aui_3_4_0_1_1224">
</div><div class="aui-tree-icon" id="aui_3_4_0_1_1214">
</div><div class="aui-tree-label aui-helper-unselectable" id="aui_3_4_0_1_1218">OSS</div> </div>
Here is the xpath that selects the clickable node (for Selenium)
$x("//div[contains(#class,'aui-tree-node-content') and (contains(.,'OSS'))]//div[contains(#class,'aui-tree-hitarea')]")

The obvious answer is:
selenium.click("link=Summary");
...
selenium.click("link=Intent");
...
selenium.click("link=Conversion");
...
A little less obvious would be:
selenium.click("xpath=//*[#id='reports-subtab-summary']/a");
...
selenium.click("xpath=//*[#id='reports-subtab-intent']/a");
...
selenium.click("xpath=//*[#id='reports-subtab-conversions']/a");
...
which has the advantage that it doesn't depend on page-text that might change (due to language translation, etc.).

You can use css path for example:
html body#gsr div#searchform.jhp form#tsf div.tsf-p div table tbody tr td table tbody tr td#sftab.lst-td div.lst-d table.lst-t tbody tr td table tbody tr td.gsib_a div input#lst-ib.gsfi

Related

protractor using xpath //*[contains('text')] error element not visible

Hi I have this element from a dropdown menu I try to select:
<div class="tt-suggestion tt-selectable">
<strong class="tt-highlight">Auto Customer</strong>
</div>
If I use element(by.xpath("//strong[contains(text(),'Auto Customer')]")).click(); I can select it no problem. But if I use element(by.xpath("//*[contains(text(),'Auto Customer')]")).click(); I get "Failed: element not visible"
Can someone explain this to me please?
Thank you
Because the * in //*[contains(text(),'Auto Customer')] means any tag, not only the strong Tag. But //strong[contains(text(),'Auto Customer')] must be strong Tag.
//*[contains(text(),'Auto Customer')] should find more then one elements on page, and the first one is not visible. You can try this xpath in Chrome DevTool's Element Tab to see how many elements it can find and the first one is visible or not.

Extracting links (get href values) with certain text with Xpath under a div tag with certain class

SO contributors. I am fully aware of the following question How to obtain href values from a div using xpath?, which basically deals with one part of my problem yet for some reason the solution posted there does not work in my case, so I would kindly ask for help in resolving two related issues. In the example below, I would like to get the href value of the "more" hyperlink (http://www.thestraddler.com/201715/piece2.php), which is under the div tag with content class.
<div class="content">
<h3>Against the Renting of Persons: A conversation with David Ellerman</h3>
[1]
</p>
<p>More here.</p>
</div>
In theory I should be able to extract the links under a div tag with
xidel website -e //div[#class="content"]//a/#href
but for some reason it does not work. How can I resolve this and (2nd part) how can I extract the href value of only the "here" hyperlink?

How do I get span text value in prototype

This is my prototype code:
$$('coupon-value').findAll("price").innerHTML
<span class="coupon-value"><span class="price">66.67</span></span>
How do I get the value of .price in the prototype? In my html code there are multiple price classes. In jquery it would be simple:
$(".coupon-value").find(".price").text();
But in prototype I have no idea. Can you help me?
If you would like to get the contents of the <span> with the price class that is a child of a <span> with the coupon-value class you would do it like this
$$('.coupon-value .price').first().innerHTML
This will give you the first element that matches that CSS selector. You can also be very specific with your CSS selection as well.
$$('span.coupon-value span.price').first().innerHTML
you can also select that element and then traverse down the DOM like this
$$('.coupon-value').first().down('.price').innerHTML
Just be aware $$() returns an array of elements that match the CSS selector so you cannot just operate on them like a jQuery collection. However all of the elements in that array are already extended with the PrototypeJS extensions.
Try:
$$('coupon-value').getElementsByClassName("price").innerHTML;
You can change innerHTML for [0]
Like this:
$$('coupon-value .price')[0];
Or even this:
$$('span.price')[0];

Xpath - Selecting attributes using starts-with

I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar. Below is a snippet of the HTML that I am looking at:
<td class="some class" align="center" onclick="Calendar_DayClicked(this,'EventCont','Event');">
<span class="Text"></span>
<div id="CompanyCalendar02.21" class="Pop CalendarClick" style="right: 200px; top: 235px;"></div>
There are multiple divs that have an id like CompanyCalendar02.21 but for each new month in the calendar, they change the id. For example, the next month would be CompanyCalendar02.22. I would like to be able to select all of the divs that are equal to CompanyCalendar*
I am rather new at this so I was using some example off the net to try and get my xpath expression to work but to no avail. Any help would be greatly appreciated.
I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar.
The following expression is perhaps what you are looking for:
//div[starts-with(#id,'CompanyCalendar')]
What it does, in plain English, is
Return all div elements in the XML document that have an attribute id whose attribute value starts with "CompanyCalendar".
While checking in Browser console with the $x() call, it worked only after flipping the quotes - i.e. double quotes inside the Xpath starts-with() call.
$x('//div[starts-with(#id,"CompanyCalendar")]')

Get all immediate children and nothing deeper

WebElement body = browser.findElement(By.xpath("//body"));
body.findElement(By.xpath("")); // I want to get all child elements
// inside body, but nothing deeper.
Example document.
<html>
<body>
<div>
</div>
<span>
<table>
</table>
</span>
</body>
</html>
Expected result is div and span. I have no controll over the documents and they vary greatly.
("*") gives all the child elements of the context node. So use:
body.findElement(By.xpath("*"));
Here's another way to get the direct children of an element:
element.findElement(By.xpath("./*"));
/html/body/*
Will select only immediate children elements of body.
Do remember that if you copy all these selected nodes, you also copy their content. So, if you do copy-of, table will also be produced to the resulting document.
Also, I would recommend to read at least XPath basics, you ask too many similar questions.
The child instead of descendant may helps someone.

Resources