UiPath selector not working in 'Click Button' Activity - uipath

I have the version of UiPath Studio Pro 2020.10.6, and I used Chrome.
I can't find the common Selector on two pages:
First case - failed one
Second case - great one
The selectors offered by the tool are the following:
Case 1:
<html app='chrome.exe' title='Sephora X Coach - Palette de fards à paupières Rexy de SEPHORA COLLECTION ≡ SEPHORA' />
<webctrl id='add-to-cart' tag='BUTTON' type='submit' />
Case 2:
<html app='chrome.exe' title='Kit maquillage des yeux de SEPHORA COLLECTION ≡ SEPHORA' />
<webctrl id='add-all-to-cart' tag='BUTTON' type='submit' />
Removing the title tag does not solve the problem.
The use of wild-cards does not work.
I looked via the "Fuzzy Search":https://docs.uipath.com/studio/docs/fuzzy-search-capabilities
I did the test in Python of the script of the page for the first case: https://www.datacamp.com/community/tutorials/fuzzy-string-python
The result is like in the picture above:
But it's not working too for the first case, since I put the level at 0.1
<html app='chrome.exe' title='"+SelectorString+ "' matching:title='fuzzy' fuzzylevel:title='0.3' /><webctrl id='add-all-to-cart' tag='BUTTON' type='submit' />
with
SelectorString = "Sephora X Coach"
I have no more idea, is the fact that in my first case the button is in a form (when looking at the code of the HTML page) and not in the second case?
Thank you in advance for your help.

I find the solution, I change the selector like that:
<html app='chrome.exe' />
<webctrl id='add[-all]*-to-cart' matching:id='regex' tag='BUTTON' type='submit' />

Related

Splunk strptime returning NaN

I have a eval on a dashboard that used to work but it stopped and I havent been able to figure out why.
On the dashboard im taking the _time and turning it into a human readable string using strftime(_time, "%m/%d/%Y %H:%M:%S %Z") and that works great. The problem comes in when I try to convert it back later for making a link to a search.
For example:
<eval token="endTimestamp">relative_time(strptime($row.Timestamp$, "%m/%d/%Y %H:%M:%S %Z"), "+30m")</eval>
Used to work and return the unix time that I added 30m to, but now strptime just returns NaN but this is the right format. I've checked out all the Splunk docs and everything looks right but it still is broke.
Any idea what I could be doing wrong?
Here is the snippet from my field row im making:
<condition field="Search">
<eval token="startTimestamp">$row.Timestamp$</eval>
<eval token="endTimestamp">relative_time(strptime($row.Timestamp$, "%m/%d/%Y %H:%M:%S %Z"), "+30m")</eval>
<eval token="corKey">$row.Correlation Key$</eval>
<link target="_blank">search?q=(index=### OR index=###) earliest=$startTimestamp$ latest=$endTimestamp$ correlationKey=$corKey$</link>
</condition>
I have taken out everything but the $row.Timestamp$ and that returns something like 10/03/2021 07:41:27 PDT which is the format that I put into it, I just cant do the reverse. I have copied and pasted the format from the strftime and still no luck converting it back so I can do math on it.
Any suggestions?
I don't think it's anything you're doing wrong... but it does seem that strptime/strftime in the dashboard evals don't seem to like %Z for whatever reason. (My Splunk Cloud stack is on version 8.2.2107.1 )
Doing the roundtrip from epoch to string and back within SPL itself seems to work fine... it's just the (javascript driven) dashboard side that doesn't seem to work quite right with timezone abbreviations.
relative_time from an epoch value works fine... and str[pf]time using UTC offsets with %z format also seems to work (which those could be workarounds for you)
I threw together a quick test dashboard to illustrate such things with the variations in formats to see differences... If you (or someone from your company) is on a current support entitlement, I would log a case for this. (I don't think I see anything related in the published known issues at least).
<dashboard version="1.1">
<label>Teddybear Time Drilldown Test</label>
<row>
<panel>
<table>
<search>
<query>
| makeresults
| eval epoch="1633272087", format=mvappend("%m/%d/%Y %H:%M:%S %Z","%m/%d/%Y %H:%M:%S %z","%m/%d/%Y %H:%M:%S"), Search="Go This Row", Reset="Clear"
| fields - _time
| mvexpand format
| eval Timestamp=strftime(epoch,format), roundtrip=strptime(Timestamp,format)
| table Search, Reset, *
</query>
<earliest>-1s</earliest>
<latest>now</latest>
</search>
<option name="drilldown">cell</option>
<option name="rowNumbers">true</option>
<drilldown>
<condition field="Search">
<eval token="timestamp">$row.Timestamp$</eval>
<eval token="strptime">strptime($row.Timestamp$, $row.format$)</eval>
<eval token="strftime">strftime($row.epoch$, $row.format$)</eval>
<eval token="relative_time">relative_time($row.epoch$,"-30m")</eval>
</condition>
<condition field="Reset">
<unset token="timestamp"/> <unset token="strptime"/> <unset token="strftime"/> <unset token="relative_time"/>
</condition>
</drilldown>
</table>
</panel>
</row>
<row>
<panel>
<title>timestamp</title>
<html>
<h2>$timestamp|s$</h2>
</html>
</panel>
<panel>
<title>strptime</title>
<html>
<h2>$strptime|s$</h2>
</html>
</panel>
<panel>
<title>strftime</title>
<html>
<h2>$strftime|s$</h2>
</html>
</panel>
<panel>
<title>relative_time</title>
<html>
<h2>$relative_time|s$</h2>
</html>
</panel>
</row>
</dashboard>

How to grap the content between <span class="attribute first">AUTHOR: </span>Stepfen King

I have the following source:
<p class="byline"><span class="attribute first">AUTHOR: </span>Stephen Butts<span class="attribute">DATE: </span><span class="monthText" style="margin-right:4px;">MAY</span>2015<span class="attribute">SUBJECT: </span>Options</p>
I want to use the XPath to grap the text/content of the AUTH: Stephen King. I've tried using the following but it doesn't work:
authors = tree.xpath('//span[#class="attribute first"]/text()', namespaces=ns)
How to do that?
You need a text of p, but not span. Try:
//p[#class="byline"]/text()[2]
or
//span[#class="attribute first"]/following-sibling::text()[1]

WebDriver Capture Text by XPath

I am attempting to capture a line of text for an automated WebDriver test to use it in a comparison later on. However, I cannot find an XPath that will work with WebDriver. I have used the text() function before to capture text that is not in a tag, but in this instance that is not working. Here is the HTML, note that this text will never be the same, so I cannot use contains or similar functions.
<div id="content" class="center ui-content" data-role="content" role="main">
<div data-iscroll="scroller">
<div class="ui-corner-all ui-controlgroup ui-controlgroup-vertical" data-role="controlgroup">
<a class="ui-btn ui-corner-top ui-btn-hover-c" style="text-align: left" data-role="button" onclick="onDocumentClicked(21228772, "document.php?loan=********&folderseq=0&itemnum=21228772&pageCount=3&imageTypeName=1003 Application - Final&firstInitial=&lastName=")" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">
<img class="checkMark checkMark21228772 notViewedCompletely" width="15" height="15" title="You have not yet viewed this document." src="../images/white_dot.gif"/>
1003 Application - Final. (Jan 11 2012 5:04PM)
</span>
</span>
</a>
In this example, the text I am attempting to capture is: 1003 Application - Final. (Jan 11 2012 5:04PM)
I have inspected the element with Firebug and I have tried the following XPaths with no success.
html/body/div[1]/div[2]/div/div/a[1]/span/span
html/body/div[1]/div[2]/div/div/a[1]/span/span/text()
The WebDriver test is being written in C#.
You can either use this
driver.FindElement(By.XPath(".//div[#id='content']/following-sibling::span[#class='ui-btn-text']")
or
var elem = driver.FindElement(By.Id("Content"));
string text = string.Empty;
if(elem!=null) {
var textElem = elem.FindElement(By.Xpath(".//following-sibling::span[#class='ui-btn-text']"));
if(textElem!=null) text = textElem.Text();
}
I was able to solve this issue by removing the span tags from the XPath.
GetText("html/body/div[3]/div[2]/div/div/a[1]", SelectorType.XPath);
python webdriver code looks something like
driver.find_element_by_xpath("//span[#class='ui-btn-text']").text
But locator may be not uniqe, because I can't see all the code
PS Try to never use locators like html/body/div[1]/div[2]/div/div/a[1]/span/span
Approach:
Find the CSS Selector from the Given DOM
Derived CSS:css=#content div.ui-controlgroup > a[onclick*='onDocumentClicked'] > span > span
Use the C# Library Method to get the Text.

How can I reach this node with Nokogiri?

Here's the start of my html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]><style>v\\:* {behavior:url(#default#VML);}\no\\:* {behavior:url(#default#VML);}\nw\\:* {behavior:url(#default#VML);}\n.shape {behavior:url(#default#VML);}\n</style><![endif]--><style><!--\n/* Font Definitions */\n#font-face\n\t{font-family:"Cambria Math";\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n#font-face\n\t{font-family:Calibri;\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\n#font-face\n\t{font-family:Tahoma;\n\tpanose-1:2 11 6 4 3 5 4 4 2 4;}\n/* Style Definitions */\np.MsoNormal, li.MsoNormal, div.MsoNormal\n\t{margin:0in;\n\tmargin-bottom:.0001pt;\n\tfont-size:12.0pt;\n\tfont-family:"Times New Roman","serif";}\na:link, span.MsoHyperlink\n\t{mso-style-priority:99;\n\tcolor:blue;\n\ttext-decoration:underline;}\na:visited, span.MsoHyperlinkFollowed\n\t{mso-style-priority:99;\n\tcolor:purple;\n\ttext-decoration:underline;}\np\n\t{mso-style-priority:99;\n\tmso-margin-top-alt:auto;\n\tmargin-right:0in;\n\tmso-margin-bottom-alt:auto;\n\tmargin-left:0in;\n\tfont-size:12.0pt;\n\tfont-family:"Times New Roman","serif";}\nspan.EmailStyle18\n\t{mso-style-type:personal-reply;\n\tfont-family:"Calibri","sans-serif";\n\tcolor:#1F497D;}\n.MsoChpDefault\n\t{mso-style-type:export-only;\n\tfont-size:10.0pt;}\n#page WordSection1\n\t{size:8.5in 11.0in;\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\ndiv.WordSection1\n\t{page:WordSection1;}\n--> </style>
<!--[if gte mso 9]><xml>\n<o:shapedefaults v:ext="edit" spidmax="1026" />\n</xml><![endif]--> <!--[if gte mso 9]> <xml>\n<o:shapelayoutv:ext="edit">\n<o:idmapv:ext="edit"data="1"/>\n</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><p> </p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><p> </p></span></a></p>
<div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> EMAIL SENDER NAME [mailto:EMAILADDRESS#FAKE.COM] <br><b>Sent:</b>!! DATE I NEED TO GRAB HERE !! <br><b>To:</b> EMAIL ADDRESS HERE <br><b>Subject:</b> SUBJECT LINE HERE <p></p></span></p></div></div>
I need to grab the date the email was sent. Here's what I've tried:
label_tag_name = 'div div p span br b'
if label_tag = #doc.at_css(%Q{#{label_tag_name}:contains("#{label}:")})
#attributes[field] = label_tag.text.gsub("#{label}:",'').gsub("\\n", "").strip
end
I also tried some shorter paths in the label_tag_name, basically adding another HTML tag to the beginning.
Every time though, the sent date is coming back nil.
The bit of your source you're interested in is (I've removed attributes for clarity):
<div>
<div>
<p>
<b>
<span>From:</span>
</b>
<span> EMAIL SENDER NAME [mailto:EMAILADDRESS#FAKE.COM] <br>
<b>Sent:</b>!! DATE I NEED TO GRAB HERE !! <br>
<b>To:</b> EMAIL ADDRESS HERE <br>
<b>Subject:</b> SUBJECT LINE HERE <p></p>
</span></p></div></div>
Note that br tags in HTML are self closing, so it's pointless looking for child elements of them.
The target could be described with the css div div p span, but note that there are two nodes that match that, and at_css returns the first. You could use div div p>span to specify only spans that are immediate children on the p. The actual target is a text node inside this element (there's only one matching span in the document now). In particular, it's the next element after the first b tag. So if we expand the css selector to div div p>span b, we can use the Nokogiri next method to get the target string:
date_string = #doc.at_css('div div p>span b').next
If you want the other fields, you could use css instead of at_css:
date_string = #doc.css('div div p>span b')[0].next
to_string = #doc.css('div div p>span b')[1].next
subject_string = #doc.css('div div p>span b')[2].next
I'll leave getting the sender name for something for you to do!
There isn't much to navigate on in that document. Use a selector that gets you to the closest point reliably then grab the text with a regex:
> doc.css("div.WordSection1 p.MsoNormal span").text[/Sent:\n(.*)/, 1]
=> " !! DATE I NEED TO GRAB HERE !! To:"
I'd start with this:
require 'nokogiri'
doc = Nokogiri::HTML(<<EOT)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
</head>
<body>
<div class="WordSection1">
<div>
<div>
<b>Sent:</b>!! DATE I NEED TO GRAB HERE !!<br>
<b>To:</b> EMAIL ADDRESS HERE<br>
<b>Subject:</b> SUBJECT LINE HERE</span></p>
</div>
</div>
</div>
</body>
</html>
EOT
text = doc.at('div.WordSection1').text
sent_date = text[/Sent:(.+)To:/, 1].strip
puts sent_date
Which outputs this:
!! DATE I NEED TO GRAB HERE !!
The sample HTML is a mess so you can't easily see the particular trees you want in that forest. Strip out everything that isn't essential for navigation, then build your search.
And, while a parser is a great tool, sometimes it's easier to use it to get to the text you want, then grab the particular thing via a string search.

Locating element in same paragraph of another element in watir-webdriver

Given the following HTML code snippet; after finding the link by ID, how would you select the checkbox in the same paragraph?
For example if I wanted to select the checkbox associated with the link with ID="inst_17901-1746-1747".
The order of the paragraphs in the DIV is not consistent between sessions so I cannot select it by index or ID of the checkbox.
<div id="inst-results">
<p>
<input id="inst-results0-check" type="checkbox">
<a class="ws-rendered" id="inst_17901-1746-1747" title="!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
<p>
<input id="inst-results1-check" type="checkbox"><a class="ws-rendered" id="inst_17882-1746-1747" title="!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
</div>
I figured out this solution working off the text of the link, but Zeljko solution is much better.
$browser.div(:id,"inst-results").ps.each { |para|
if para.link.text == "!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range" then
para.checkbox.set
break
end
}
If there is only one checkbox in the paragraph with the link:
browser.link(:id => "inst_17901-1746-1747").parent.checkbox.set
Works with watir-webdriver, not sure if it would work with other Watir gems.

Resources