Select dynamic checkbox uipath selector - uipath

I want to checkbox row in a table.
The row number is stored in a variable rowNum.
In selector, it shows
<webctrl id='tblResult_0' tag='INPUT' type='checkbox' />
This selects row 0. I want to select what is stored in rowNum.
How do I do that in UiPath?
Its a click activity.

It depends on which system you use.
So to go with your example: <webctrl id='tblResult_0' tag='INPUT' type='checkbox' />
Without Object repository
First add an Assign activity before you use the dynamic selector
Now set the dynamic selector to a new variable num in the Assign activity
Set num to 0
Use that new variable num now as selector input wherever you want like so
"<webctrl id='tblResult_" + num + "' tag='INPUT' type='checkbox' />"
With Object repository
With OR it's much easier. Here, we don't need an Assign activity anymore.
First, create a variable without the Assign activity
Now set the dynamic selector to a new variable num in the Variables tab
Set num to 0
Use that new variable num now as selector input in your Object repository selector
"<webctrl id='tblResult_{{num}}' tag='INPUT' type='checkbox' />"
Here an example screenshot of one of my own processes:

Related

xPath: fetch element with an attribute containing the text of another element

Given I have the following HTML structure:
<button aria-labelledby="ref-1" id="foo" onclick="convey(event)">action 2</button>
<div class="anotherElement">foobar</div>
<div id="ref-1" hidden>target 2</div>
I would like to fetch button by its aria-labelledby attribute. I tried the following options:
//*[#aria-labelledby=string(/div[#id="ref-1"]/#id)]
//*[#aria-labelledby = string(.//*[normalize-space() = "target 2"]/#id)]
//*[#aria-labelledby = .//*[normalize-space() = "target 2"]/#id]
But wasn't able to fetch the element. Anyone has an idea what the right xPath could be?
Edit: simply put: how do I fetch the button element if my only information is "target 2", and if both elements can be randomly located?
//button[#aria-labelledby='ref-1']
or
//button[#aria-labelledby=(//*/#id)]
or
//button[#aria-labelledby=(//*[contains(.,'target 2')]/#id)]
or
//button[#aria-labelledby=(//*[contains(text(),'target 2')]/#id)]
?
Since button and div are the same level siblings here you can use preceding-sibling XPath expression like this:
//div[text()='target 2']//preceding-sibling::button
pay attention with with your actual XML this will match 2 button elements.
To make more precise math I think we will need to be based on more details, not only the target 2 text

select element based on class and attribute value

I'm trying to use Xpath in order to select an HTML tag based on its value
Here is my html code:
<span class="yellowbird">Continue</span>
<span class="yellowbird">Stop</span>
I can select the span elements with a specific class value using
//span[contains(#class, 'yellowbird')]
However I'm struggling to select only the element which contains the value "Continue"
This XPath expression will select any span element whose class attribute equals yellowbird and text equals Continue:
//span[#class='yellowbird' and text()='Continue']
Here is the syntax I used to make this work using request.xpath and scrapy
//span[contains(#class, 'yellowbird')][1]//text()='Continue'

ASP Classic : Put a "variable" in a "Request.Form()"

I have a form that will send an array of data to an ASP page.
Let's say this array is called "matrix".
Usually, on the ASP receiving the form, I will write this out to retrieve the form inputs from the array "matrix".
Request.Form("matrix[]")(i) where i = 1, 2, 3 which are the elements in the array.
Let's say I want to do make a variable like this
a="matrix"
and I want to use this variable a and put it into the request form, instead of writing "matrix", so that it would look something like this
Request.Form(a[])(i)
How can it be done? For now, all my attempts are showing blank. e.g. when I try to make them appear on the page with response.write, nothing shows up.
Please help me or let me know if it cannot be done, I've been spending hours on this.
Request.Form("matrix[]") is taking a string value of "matrix[]" not an array of strings called "matrix".
So you need to do either
a = "matrix[]"
Request.Form(a)(i)
or
a = "matrix"
Request.Form(a & "[]")(i)
Unlike PHP which requires adding square brackets, in classic ASP you just have to give the same name to the elements you want to be combined into an array.
The HTML should be:
<input type="text" name="matrix" />
<input type="text" name="matrix" />
<input type="text" name="matrix" />
Then you can iterate over the submitted values like this:
For x=1 To Request.Form("matrix").Count
Response.Write("Value of matrix #" & CStr(x) & "is: " & Request.Form("matrix").Item(x))
Next
Note that all elements are included, even if user left them empty.

EditorFor with Collections and Name attribute

I am trying to create a form that allows the editing of multiple rows of data. I have no problem looping through and getting input boxes to render...I just cannot get the name attributes to output correctly.
I know that in order to submit a collection you need to post back an indexed name where the index is sequential starting at 0.
<input name="Books[0].Title" />
<input name="Books[1].Title" />
and so on...
Now, I can get the EditorFor function to output my proper name with given the following loop code
#For n = 0 To (Model.Books.Count - 1)
#Html.EditorFor(Function(m) Model.Books.Item(n).Title)
Next
giving me
<input name="Books[0].Title" />
<input name="Books[1].Title" />
and so on...
My problem is VS shows the following warning
Using the iteration variable in a lambda expression may have unexpected results. Instead, create a local variable within the loop and assign it the value of the iteration variable.
Yet when I change the loop to
#For n = 0 To (Model.Books.Count - 1)
Dim item = Mode.Books.Item(n)
#Html.EditorFor(Function(m) item.Title)
Next
I get
<input name="$VB$Local_item.Title" />
<input name="$VB$Local_item.Title" />
and so on...
Any thoughts? Should I just ignore the warning?
Thanks.
Jason
MVC works by actually breaking apart the lambda expression, and seeing what it's made of. It doesn't just execute the lambda and get the result. So you need to actually use the model parameter in the lambda for it to work. This should do it for you:
#For n = 0 To (Model.Books.Count - 1)
Dim index = n
#Html.EditorFor(Function(m) m(index).Title)
Next

what does this xpath expression mean?

//input[#type="hidden" and #name="val" and position() = 1]/#value
does this mean get the text typed inside the input box ?
Read from right to left, it means "Get the value attribute of all of the input tags whose type attribute is 'hidden', whose name attribute is 'val', and which appears as the first element in its enclosing (form) tag".
I think it means grab the value attribute of an input whose type attribute is 'hidden' in addition its name attribute is 'val' and its position amongst its siblings is 1 ( first I believe, not sure if 0 is the start in xpath ).
<input type="hidden" name="val" value="test">
<input type="hidden" name="foo">

Resources