XPath only get nodes from table when another node exists - xpath

I have a specific problem concerning XPath.
Say I can get a column from the table using this query:
//div[#id="someid"]/table/tbody/tr/td[9]/text()
However, I want to only get this column when another specific node exists.
I tried using:
//div[#id="someid"]/table/tbody/tr/td[9 and boolean(//a/span[#title='specifictitle'])]
This however does not work as it returns all items in the table.
I have a few specific limitations:
- //div[#id="someid"]/table/tbody/tr is static and cannot be changed.
- The td contains no other info concerning what column it is in.
Thanks in advance!

2 approaches:
First - as a direct condition within square brackets:
//div[#id="someid"]/table/tbody/tr[//a/span[#title='specifictitle']]/td[9]/text()
this approach is simpler and the position does not matter
this is also the approach that fulfills the OPs requirement, that the query should start with //div[#id="someid"]/table/tbody/tr
* You can basically put the condition [//a/span[#title='specifictitle']] to whatever element in the query you want (could also be behind tbody or table etc.)
Second - using axes (for example ancestor)
2 cases regarding the position of your element within HTML code:
1) anchor-element "before" your div with "someid":
//a/span[#title='specifictitle']//div[#id="someid"]/table/tbody/tr/td[9]/text()
2) anchor-element "after" your div with "someid":
//a/span[#title='specifictitle']/ancestor::div[#id="someid"]/table/tbody/tr/td[9]/text()
In both cases the xpath-query will not return a result if the //a/span[#title='specifictitle'] does not exist, which is what you needed, if I understood correctly

Related

Unable to use INDEX COUNT for referencing all of the rows in a Google Sheet

I am trying to use the format/formula A:INDEX(B:B, COUNTA(A:A)) to reference all of the rows until the first empty one and it is not working.
If I skip the first row, then the formula works: A2:INDEX(B2:B, COUNTA(A2:A)).
What am I doing wrong?
I believe because you're using the number of rows to define the end of the data (using INDEX), you have to include a defined starting row. I think this should work for you:
=QUERY(A1:INDEX(B:B, COUNTA(A:A)), "SELECT *")
That is assuming you don't have data that exists beyond the first blank row.

Table Extraction in UIPath if table has images

I am trying to extract the Table which has the following format
When I want to extract i should have either put some character on place up icon or i dont want that either the case is fine..
But UIPath brings this way.. 78,59,237806 all as one text which is misleading.. How to resolve this issue..
Thanks
Take a look at the Find Children activity. You can specify an item via selector (the table) and use Find Children to return a collection of type UiElement.
So set the filter to extract the "<webctrl tag='tr' />" which will effectively give you a collection of the rows.
Use a For Each to iterate through each UiElement you got from the first Find Children activity, and use that element to run another Find Children. In this case, set the filter to extract the elements with a class of "mid-wrap". This gives you a collection of the elements in the row which match that requirement, and this will exclude the data-up value, since that's a different class.
You can then loop over this collection to get the innertext attribute, which will give you the actual values you're looking for each cell in the row. Use something like Add Data Row to add the values to a datatable, and let the For Each run over the next row in the collection.

Power Query - conditional replace/clear entire cell in multiple columns

I'm trying to clear the entire cell if it doesn't contain a given keyword.
I've managed to do this for one column:
Table.ReplaceValue(#"PrevStep",each [#"My Column"], each if Text.PositionOf([#"My Column"],"keyword")>-1 then [#"My Column"] else null,Replacer.ReplaceValue,{"My Column"})
The problem is I need to iterate/repeat that step for a number of columns... the number of columns may vary and column names also may be different every time. I can have all those column names put into a list but I'm not able to use it.
The solution I'm looking for may look like this
for each ColNam in MyColumnsList
Table.ReplaceValue(#"PrevStep",each [#"ColNam"], each if Text.PositionOf([#"ColNam"],"keyword")>-1 then [#"ColNam"] else null,Replacer.ReplaceValue,MyColumnsList)
next
but this is not the VBA code but Power Query M - and of course the problem is with #PrevStep as I would see it like a recursions... again... do not know how to process.
Is the path I follow correct or should it be done some other way
Thanks
Andrew
Unpivot your columns to turn all the columns into two columns. Apply your replacement to the single value column then pivot it back into the original format

XPATH - locating specific children element

in my DOM I have like 3 tables and each table has several input fields, is it possible to write xpath let say for 3rd input of 2nd table
I can locate only first input of each table, so I assume that its bracket thing
i did try
(//table[#class='table-name'])2[3]
also
((//table[#class=‘table-name’])[2])(//input)[3]
"the third input out of the second table":
((//table)[2]//input)[3]
first, this selects all tables from the document, regardless of their position //table.
then it picks the second one from that set (//table)[2]
going from this one, it selects all nested inputs (//table)[2]//input
and from this set, it picks the third one
Note that (//table)[2] is "from all tables anywhere, take the second one" whereas //table[2] is "take all tables who are the second child of their respective parents". The the former expression can only ever select a single table, while the latter can select more than one.

How to filter entries that are not duplicates of entries from others columns in Google Sheets?

I have a column called "Masterlist" which contains values from Lists 1, 2 and 3. It also contains values which are present only in Masterlist.
How can I filter them, like shown at the attached image in Google Sheets?
EDIT: The lists will have more than one entries.
Solution 1
In E2, type in
=filter(A2:A,arrayformula(iserror(match(A2:A,B2:D2,0))))
Check the documentation of filter or match for how to use them. With match, be sure to include the third argument. That is an easy one to forget. arrayformula iterates a formula over a range. The output can be a range, in which case it will print over any un-written cells. When arrayformula interacts with match, it only iterates over the first argument, which is why this solution works.
EDIT: If you have a two-dimensional range to match to, you need to collapse them into a one-dimensional range using the concatenation operators such as
=filter(A2:A,arrayformula(iserror(match(A2:A,{B2:B4;C2:C4;D2:C4},0))))
You can experiment with endings without row indices and let Google Sheets select an ending index for you.
Solution 2
Use the native Filter View feature. Good for the scenarios where you don't need to separately print a list of the unique values in "masterlist".
Go to Data -> Create Filter View
Use the relevant help pages to navigate yourself. I can see a few ways to implement what you desire, including
filter by value on the same column (selecting the actual values manually);
filter by value on a "helper column" where you include a formula in the cells to check whether the content in "masterlist" belongs to the list you want to check against. You can use the match and iserror combo here;
custom formula using a similar formula as above.
If your column A, ie. the "masterlist", is something a user would add to, then Data Validation can be used to good effect in conjunction with Filter View.

Resources