How to get the web control values from HTML tag?


#1

In my web application, I am having multiple HTML controls in a page. Now what I am trying to do Is to get all the HTML controls and iterate row by row and get the control or value from HTML.
Suppose the web page has 2 text box, 2 radio button, 1 button and 1 combo box.

Untitled
So here, I need the web control name/id value from the HTML. Could you please help me how I can get these value?


#2

@dev.sam
try Get Attribute Activity


#3

I am using the Get Attribute only. I can get all the information like class,innertext,innerHtml, parent id etc…but failed to get the web control id/name value. i need to fetch the value of web control. Please see the attached image (previous) for reference. Could you please try and let me know what i need to add in my Get Attribute property?


#4

Anybody has some idea about this problem. Kindly share the idea/solution if you came across such type of problem.

Thanks for your help in advance


#5

@dev.sam If you want to retrieve the value of id or name attribute for those elements, then you just need to pass that attribute name for your ‘Get Attribute’ activity.

image

Let me know if that’s not what you are looking for.

Thanks,
Rammohan B.


#6

Thanks for the reply.

Actually, my requirement is not to get the value inserted in the text field or any web control. Here I am looking for the object name/id of the web control. Similar like when we spy the object and get the name/id value from any automation tool (UFT, Selenium, CodedUI etc.)

Suppose the web page has 2 text box, 1 combo box and 1 submit button. I need to pick all the object name/id value from the HTML control.

Untitled

So here the BOT should give us the number of objects (web components) and its name/id value from the current web page. In our case the result should look like –

HTML Objects available in the web page – 4 (2 textbox + 1 combo + 1 submit button)
Name/Id of objects – txtUserID, txtPassword, ddlDomain and btnSubmit

I hope, am able to explain it. Please let me know if you have any doubts/questions.

Thanks
Dev


#7

Hey @dev.sam,

I think i understood what you were looking for.

I am not sure about UFT or CodedUI, But i believe you still have to inspect elements and do something like this,driver.findElements(By.tagName("<tagName>")) which will basically return list of all the elements matching with that tags.

You can use UiExplorer to identify such elements. Basically in your case you can set the target as ‘Body’ of the Html page you are using to get all the Elements available inside the it.

Use this identified selector for ‘Find Children’ activity with the filter as "<webctrl tag="<tagName>"/>". This will return all the elements with that tag and store in an output variable with type as 'IEnumerable<UiElement>'.

Use a ‘For Each’ activity to perform your action on each of those identified elements. If you need to get an attribute value for each of those then use ‘Get Attribute’ under your for each loop.

Let me know if it makes sense. You can attach your html page. May be i can create a simple workflow if you still need it.

Thanks,
Rammohan B.


#8

Hi Rammohan,

Sorry for the delayed reply.

Thanks for the response. You are absolutely right.
I tried the same thing whatever you had suggested but I am unable to fetch the ID and Name value of the HTML controls.

Step 1 – Open the browser and browse the desired URL
Step 2 - Find the HTML component by using Find Children activity, Here I need all the HTML controls available in that particular page. So here I need text box (username, first name, last name, email and password), Combo box and Submit button.
Step 3 – Iterate the items (Output variable ‘IEnumerable’) and get the value out of it by using ‘Get Attribute’. So here I am looking for HTML control id and name value.

I am looking for the highlighted value.

HTML Page - https://www.opencart.com/index.php?route=account/register

Please, let me know if you need any further information. Please make a sample script and share with me

Thanks in advance.
Dev


#9

Hey @dev.sam,

Tried to implement the workflow that you needed. Attached the same.
OpenCartFindChildren.xaml (19.6 KB)

Let me know if this helps.

Thanks,
Rammohan B.


#10

Thanks a lot, Rammohan.

Yes, this is what I was taking about. The workflow works as expected.
I have couple of query regarding the same implementation. After seeing the workflow (Your’s) I had tried myself but failed to understand the “Find Children” attribute. What I did basically

  1. Dragged the “Find Children” attribute after open browser
  2. Set the “Filter” to “”
  3. Set the “Selector” manually “”

But when I execute this, the list of control (count) am getting 1 where as your script gives 6 which is right. I am doing wrong something. If I copied your “find children” activity, then I got the right value.

Could you please help me where I am doing the mistake? Kindly review and do suggest me.
Attached the workflow - AutoSequence.xaml (12.9 KB)

Thanks
Dev


#11

Did you change the value of property ‘Scope’ to ‘FIND_DESCENDANTS’? Its ‘FIND_CHILDREN’ by default.

Find Children -> It identifies the direct children (based on matched filter) only for the selector of find children.

Find Descendant -> It identifies the direct children (based on matched filter) or anything descendant inside the selector.

Thanks,
Rammohan B.


#12

Thank you so much. It is working.

Thanks & Regards
Dev