I am trying to retrieve the id of a parent (grand-grand-parent) element.
All the information I have is that //div[#class="preset_name"] is "all". Knowing that, I need to retrieve "preset_3" (as a string) using any of the Robot Framework keywords.
How would I do that? Or how can I obtain the full xpath of "all"?
<table id="preset_list">
<tbody>
<tr id="preset_0">
<td>
<div class="preset_title_line">
<div class="preset_button_group">
<button class="preset_button">Apply</button>
</div>
<div class="preset_name">Factory default</div>
</div>
<div class="preset_sections">System, Network, Sources, EDID, Channels, Automatic File Upload, Touch screen, Output ports</div>
</td>
</tr>
<tr id="preset_1">
<td>
...
You can filter tr that contains //div[#class="preset_name"] = "all", and then return the corresponding id attribute :
//tr[.//div[#class='present_name'] = 'all']/#id
Your XPath should be:
Get Element Attribute xpath=(//div[#class="preset_name"][text()='all']/../../..)#id
(I've never used Robot, but I think it is the correct sintax)
Its easy if you are using "relative xpath helper chrome extension".
https://www.linkedin.com/pulse/finding-relative-xpath-made-easy-syam-sasi?trk=prof-post
Related
I have the following html code:
<tr id="id that I want to obtain via title">
<td class="icon">
<span class="greenArrowIcon pid-1-arrowSmall"></span>
</td>
<td class="bold left noWrap elp">
<a href="..." title="title that I have obtained">
TITLE
</a>
<MORE CODE>
</td>
</tr>
and I know that the tag title title="title that I have obtained" are always the same, but the id id="id that I want to obtain viva title" could change, is strange that changes, but could.
So, my question is: How can I find the id via the title ? I think the problem is that the title tag is inside (an inferior jerarchy) from the id that I want to solve it.
I am using Selenium, and this is the code to solve the title and get the web element:
driver.find_element_by_css_selector("[title^='title that I have obtained']")
Is it possible do this?
To find the desired id attribute value you can use the following XPath locator:
tr = driver.find_element_by_xpath("//tr[.//a[#title='title that I have obtained']]")
id = tr.get_attribute("id")
Already #Prophet answered in a good way but I want to show you other ways to find the same element.
Using parent function:
//a[#title='title that I have obtained']//parent::td//..
//a[#title='title that I have obtained']//..//parent::tr
Using ancestor function:
//a[#title='title that I have obtained']//ancestor::tr
a few days from now I am trying to write a selenium ide test for a data structure tree. I stuck with expanding tree nodes, the main thing is that there is a lot of TreeExpandoIcons of the same class, no id, text, type and so on.
<tbody>
<tr>
<td title="Control + right arrow key to expand this row." aria-expanded="false" aria-readonly="true" role="gridcell" tabindex="-1" aria-describedby="RestartPageGrid-Id" colid="Id" class="gridxCell" style="width:auto;min-width:auto;max-width:auto;">
<div class="gridxTreeExpandoCell " style="padding-left: 16px;">
<div class="gridxTreeExpandoIcon " style="margin-left: 0px;">
<div class="gridxTreeExpandoInner">+</div></div>
<div class="gridxTreeExpandoContent gridxCellContent">1</div>
</div>
</td>
There is always only one difference between icons, near icon is gridxCellContent number . But It is only near and it is not clickable. Maybe you know some workaround or how to solve this problem? I would be very appreciated.
My selenium ide offers, to write like this:
<tr>
<td>click</td>
<td>css=div.gridxTreeExpandoIcon.</td>
<td></td>
</tr>
But this code isn't working.
There are few queries I have :
1. Have you tried removing the last (.) in the css selector ?
2. Also i see that
"gridxTreeExpandoIcon " class has a trailing space.
Are you aware of using contains in css selectors?
3. Have you tried using different location strategy ?
such as xpath, //div[contains(#class,'gridxTreeExpandoIcon')]
I have the following html code
<tr>
<td class="fontblue" style="height: 17px">
Primary Industry Code
</td>
<td class="fontlightblue" style="height: 17px" colspan="4">
<span id="ucOrganisationDetail_lblVPrimarySector">
FMP CB:Miscellaneous Manufacturing
</span>
</td>
</tr>
I would like to extract the text FMP-CB Miscellaneous Manufacturing using getelementbyID option in vba. can anyone please help me
I tried using the below vba code but nothing is working
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").Value
Try the following:
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").innerHTML
You want .innerText as mentioned in comments I see.
.innerText
Sets or returns a String that represents the text between the start
and end tags of a specified object without any associated HTML.
expression.innerText
expression Required. An expression that returns one of the objects
in the Applies To list.
You could use
objIE.Document.getElementById("ucOrganisationDetail_lblVPrimarySector").innerText
or a CSS selector which says the same thing of:
objIE.Document.querySelector("#ucOrganisationDetail_lblVPrimarySector").innerText
The element is correctly selected as you can see with:
I hope someone can help me with these two problems.
They are part of the same work but different from each other.
I am using angularjs to filter through a list that is quiete big (more than 1000 elements) but it's very slow. I was wondering if there's a way to optimize this.
Here's the code
<div class="test">
<table class="table table-hover" >
<tbody>
<tr ng-repeat="test in tests| filter:query">
<td>
<div id="delete">D<br />E<br />L<br /></div>
<div id="edit">E<br />D<br />I<br />T</div>
<p ng-show="test.id">ID:<b>{{test.id}}</b></p>
<span ng-repeat="name in test.names" ng-show="test.names">Company: <b>{{name}}</b></span>
<span ng-repeat="age in test.ages" ng-show="test.ages">Country: <b>{{age}}</b></span>
<span ng-repeat="course in test.courses" ng-show="test.courses">Found: <b>{{course}}</b></span>
<span id="output" ng-show="test.out1">Then: <b>{{test.out1}}{{test.out2}}{{test.out3}}{{test.out4}}</b></span>
</td>
</tr>
</tbody>
</table>
</div>
The second question is regarding "tabset" in html
I have 3 tabs and in one tab I have an edit link on each item, I want the third tab to come up when I click on the edit link of the first tab.
I searched online and understand that some js or jquery is needed but nothing has worked so far.
thank you in advance
If you are handling such a big set of data you should use a pagination system.
Also I won't attach the entire 1k object to the scope and and use a filter in the ng-repeat but instead add just a chunk of data like 50 to the scope and every time you change the page you would change the $scope.tests with the next/previous 50 items from your 1k.
One more point, if you are using a lot of interpolation {{}} but not each of them needs a separate watcher you should consider using angular's "bindonce".
I am testing a web page with dynamic ids. The page contains a remove icon followed by a browse icon at multiple places and I am not able to click these icons or I must say I am not able to write the correct XPath to locate any particular icon.
The following is a snippet of the HTML code.
<tr class="tableNestedAttribute">
<td class="autosuggest-svl-cell">
<input name="odf_obs_fin_dept_text">
<div id="div_d31505e760_location"></div>
</td>
<td class="actions" nowrap="" align="right">
<div class="ui-browse-lookup-images ppm_field formFieldDisNoWidthReadOnly ">
<img id="d31505e7601" title="Remove Department OBS" name="Remove">
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
</div>
</td>
</tr>
The above HTML code is at multiple places in the page except that the name in the first td is different at each place.
My requirement is here to click the browse which is in the same line as the input field with name odf_obs_fin_dept_text.
Tried the following and various other combinations but with no luck.
driver.findElement(By.xpath("//*[#name='odf_obs_fin_dept_text']/following-sibling::td[1]/descendant::div/img[#name='Browse']")).click();
With the provided example the following XPath:
//input[#name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/div/img[#name='Browse']
will find the next element:
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
Or if you want to keep your XPath intact, only add parent::td between //*[#name='odf_obs_fin_dept_text'] and following-sibling::td[1]
//*[#name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/descendant::div/img[#name='Browse']