Wait for multiple elements using xpath in Selenium IDE - xpath

Is it possible to wait for multiple elements present on the page using xpath locators?
For example if I wanted to wait for ONE of elements A or B using xpath I'd use:
<tr>
<td>waitForElementPresent</td>
<td>//div[A] | //div[B]</td>
<td></td>
</tr>
How would the command for waiting for BOTH elements look like?

Disclaimer : I know XPath, but I don't know Selenium IDE.
So, based on what I know about XPath only, I would suggest this XPath statement :
<td>//div[A or B]</td>
is that make sense?

Related

Scrapy Xpath Query ( Scraping from Similar Class but different align tags)

The code from where I want to scrape my data:
<td class="pageHeading" valign="top">ABC<br><span class="smallText">[RK103401]</span></td>
<td class="pageHeading" align="right" valign="top">SAMPLE2<br>
I want to know the Xpath which will lead me to extract SAMPLE2.
I notice that the class name is the same but can't figure out how to go about this.
Thanks!
When looking for an XPath to select something specific, you want to find an element that is unique to what you want to catch. Here, it's pretty hard to tell as there aren't much HTML, so we don't know which elements won't be repeated throughout the doc.
Something like this might do the trick:
//td[class="pageHeading" and align="right"]/text()

Matching text with xpath?

I'm screen-scraping an HTML page which contains:
<table border=1 class="searchresult" cellpadding=2>
<tr><th colspan=2>Last search</th></tr>
<tr><th align=left>Search term</th><td>xxxxxx</td></tr>
<tr><th align=left>Result</th><td>yyyyyyyy/td></tr>
</table>
I want to write an XPATH expression which gets me the data cell containing "yyyyyyyy". I've gotten as far as
.//table[#class='searchresult']//tr/th
which gets me a list of all the table-header nodes in the table. I can iterate over them in user code, find the one whose .text is "Results" and then call .getnext() on that to get the table-data. But, is there a cleaner way to do this by writing a more specific XPATH pattern? It seems like there should be, but I haven't gotten my head that far around XPATH yet to figure out how.
If it matters, I'm doing this in Python with lxml.
.//table[#class='searchresult']//tr/td[preceding-sibling::th] might give you what you need.
Two comprehensive papers on semi-automatically creating XPath statements like this one, specifically for screen scraping purposes can be found here:
http://tobiasanton.com/Tobias_Anton/Academia.html
Use:
//table/tr[last()]/td
This selects any td element that is a child of any tr that is the last tr child of any table in this XHTML document.
This may select more than one td element, depending on whether or not there is only one table in the XHTML document. You need to make this expression more precise, if more than one table element is present.
For example, if the table in question is the first in the document, use:
(//table)[1]/tr[last()]/td

[xpath]Need help in getting xpath for a table row next to another

EDIT: Why was this voted down? I really have no idea... BTW ../ does not work since i don't want the parent of the Table but want actually ../td+1 i don't know if that is even possible?
Hi guys.
I have a fairly complex problem at hand..
I have a table like this:
Name | Result | AutotestID | AutotestResult | AutotestName
X | Pass | X86HZS1 | | |
So... What i want to do is the following. I know only the ID. And i'd like to update the AutotestResult from an autotest. Which is empty to begin with.
I'm trying to locate the ID... I have that. But then when i have the ID i must update the Row next to it. How do i do that? I tried playing with the xPath. Stepping backwards using ../../../td etcetc but with no luck.
I can't seem to find its neighboring table...
Could somebody please point me into the right direction?
Thanks very much for every help!
Hannibal
Besides jasso's good recommendation of following-sibling axis, there is some problem with that answer: you must fix what td is the AutotestID.
So, knowing the table' schema:
<table>
<tr>
<td>Name</td>
<td>Result</td>
<td>AutotestID</td>
<td>AutotestResult</td>
<td>AutotestName</td>
</tr>
<tr>
<td>X</td>
<td>Pass</td>
<td>X86HZS1</td>
<td></td>
<td></td>
</tr>
</table>
You could use:
/table/tr/td[3][.='X86HZS1']/following-sibling::td[1]
or
/table/tr[td[3]='X86HZS1']/td[4]
If you don't know the AutotestID position, you could use:
/table/tr/td[count(../../tr/td[.='AutotestID']/preceding-sibling::td)+1]
[.='X86HZS1']/following-sibling::td[1]
Your question is unclear but I'm doing some guessing and presume you have an XHTML file
<table>
<tr>
<td>Name</td>
<td>Result</td>
<td>AutotestID</td>
<td>AutotestResult</td>
<td>AutotestName</td>
</tr>
<tr>
<td>X</td>
<td>Pass</td>
<td>X86HZS1</td>
<td></td>
<td></td>
</tr>
</table>
and you are trying to create an XPath expression that selects the next <td> element after the one that contains text "X86HZS1" (the AutotestID). To find a node with certain text content you can use a predicate and the sibling elements that appear after this node in the document order you get by using axis following-sibling. A proper XPath expression would be
//td[.='X86HZS1']/following-sibling::td[1]
If the same AutotestID you are matching appears several times in your table data, this expression matched all of them and would return a node set instead of a single node.
Edit: Generally using // when not neccessary is not recommended since it requires traversing through the whole document. Using a more direct path, like mentioned in comments, results in more efficient XPath expression.

What’s the XPath expression to select an attribute based on its prefix?

I need to select a node with a id attribute that I only know part of the value.
If I have several <tr> elements:
<tr id="foobar[1234]"></td><tr id="foobar[1235]"></td><tr id="foobar[1236]"></td><tr id="bar[1]"></td><tr id="foobar[1237]"></td><tr id="bar[12]"></td>
I only want to select the id's that start with foobar.
I've tried:
//tr[#id='foobar*']
but it doesn’t work.
Any help? Thanks.
//tr[starts-with(#id,'foobar')]
A list of XPath 1.0 functions: http://www.edankert.com/xpathfunctions.html
If your implementations supports XPath 2.0, you get a lot of other ones.
Have you tried
//tr[#id*="foobar"]
I'm not certain this works, but it may.

xpath multiple conditions

In selenium IDE,
I need to find the 3rd link whose text is 'XXX'
<tr>
<td>clickAndWait</td>
<td>//a[text()='XXX'][3]</td>
<td></td>
</tr>
error: element not found, any idea?
As answered in my comment on selenium scripts
It may be because of a subtlety in XPath where //a[1] will select all descendant a elements that are the first para children of their parents, and not the first a element in the entire document. It might work better for you to use something like //body/descendant::a[1] or anchor it to an element with an id like id('myLinks')/descendant::a[1]. Note that for the last example you would need to proceed the locator with xpath=.
Use:
(//a[text()='XXX'])[3]
The expression:
//a[text()='XXX'][3]
selects every a element that has some text child with value 'XXX' and which is the 3rd child of its parent. Obviously, there are no such nodes, and you do not want this but you want the 3-rd from all such a elements.
This is exactly selected by the first XPath expression above.

Resources