How to access the table,tr,td which has no attributes using Watir - ruby

I am trying to access the table as well it rows and table data(td),generally the table,tr and td has no attributes to use I tried with index but still no use,even I tried with the parent element of table still I was unable to access it.
<div class = "Links"></div>
<div class = "board">
<table>
<tbody>
<tr><td>Name</td><td>Value</td></tr>
<tr><td>shaik</td><td>500</td></tr>
<tr><td>shahrukh</td>900<td><span style="" has css properties ></span></td></tr>
</tbody>
</table>
</div>
I tried in the following way
#ie.table(index,0) and
#ie.div(:class,'Links').table(:index,0)
returned an error as unable to locate the element

#ie.table by itself should work.
#ie.div(:class, 'Links') is not a parent of the table element since the </div> comes before the <table> in the dom.

Try this,
myelem = browser.tr(:text, /Name/).td(:index => 2).text
#or you can use the more user-friendly aliases for those tags
myelem = browser.row(:text, /Name/).cell(:index => 2).text

Related

Identifying an WebTable/WebGrid Object in QTP

I have the below code in html for a WebTable(Web Grid).
<table width="90%">
<div class="greybox" style="margin-top:2%;">
<table class="datagrid" width ="100%">....<table>
</div>
</table>
I tried providing exactly the same(all) properties in my descriptive programming but the Web Element(DIV) is not being identified by QTP. Is there a unique way to identify this?
Note: The Web page is developed a single page application
Edit:
So I think I have resolved the issue with the below code. There were two Objects being identified without the "Unique Text" if clause. First Object was parent of the DIV object so had to use a "Unique text" from the first object which wouldn't be part of any other object. I am currently trying with different data to see if it's working fine
Browsername = Browser("micClass:=Browser").GetROProperty("name")
Pagename = Browser("micClass:=Browser").Page("micClass:=Page").GetROProperty("name")
Set desc = Description.Create()
desc("micclass").Value = "Webelement"
Set ChildObject=Browser("name:="&BrowserName).Page("name:="&PageName).ChildObjects(desc)
Set Child_Table_Value = nothing
For i=0 to ChildObject.Count-1
innerhtmlvalue = ChildObject(i).GetRoproperty("innerhtml")
htmltag = ChildObject(i).GetRoproperty("micclass")
if(Instr(innerhtmlvalue, "MARGIN-TOP: 2%")<>0) then
if(Instr(innerhtmlvalue, "UniqueText")=0) then
if(Instr(htmltag, "WebElement")<>0) then
Set Child_Table_Value = ChildObject(i)
End If
End If
End IF
Next
Set Table_Value = Child_Table_Value.WebTable("html tag:=Table")
Ok, so assuming you have an HTML structure something like this:
<table width="90%">
<tr>
<td>
<div class="greybox" style="margin-top:2%;">
<table class="datagrid" width="100%">
<tr>
<td>UniqueText</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
...and as per your current solution you can rely on "UniqueText" being present, then you could try the following XPath statement:
(//table[contains(., 'UniqueText')])[last()]
So in QTP/UFT you'd be doing:
Browser("micClass:=Browser").Page("micClass:=Page").WebTable("xpath:=(//table[contains(., 'UniqueText')])[last()]")
Try to use like below.(Try to identify the div block using the "class")
Browser("micClass:=Browser").Page("micClass:=Page").Webelement("class:=greybox").Webtable("class:=datagrid")
Please let me know

Add element to existing html using specific location using id and class using prototype insert

i am trying to add Element to existing html content using prototype insert. below is the html on which i am working
<table id="productGrid_table" class="data" cellspacing="0">
<thead>
<tr class="filter">
<th>
<div class="range">
</div>
</th>
</tr>
</thead>
here i want to add another < th> in < tr class="filter">, i am trying to achieve this using below prototype code
$('filter').insert("<th><div class='field-100'></div></th>");
please provide some suggestion what i am doing wrong here???
In PrototypeJS $('filter') selects element with id="filter". If you want to select by class, then use $$ function. Something like this:
$$('.filter')[0].insert("<th><div class='field-100'></div></th>");
But I'd recommend either changing class name to something more unique, or use id instead of class.

Unable to reference all Model objects in MVC View

I have an odd problem whereby the model in my vbhtml file will correctly reference and bring up the model's attributes for 1 item but not for another.
FYI, The page is added as a partial page, connected to another vbhtml page.
My page is structured such that I want to list a number of people (beneficiaries), below each question (question text).
I am referencing my Model type using the syntax: #ModelType RHEAL_START.QuestionWithAnswers, so this should automatically allow the model items to be declared when instantiated.
The #ModelType declaration correctly allows the referencing of the 2nd model field (Model.benAnswers) but not the first one I have declared (Model.questionText).
Both items are part of the same model and, I have tried moving the declarations above and below the and headers but, this did not bring up an IntelliSense for the Model.questionText.
I looked at the following post and tried addding in a reference to the Layout file but alas, this did not bring up an IntelliSense either.
MVC3 - render view that is not a method in a controller
See the code below. Can anyone suggest where I'm going wrong and what else I can try?
If you need more information, please let me know.
#ModelType RHEAL_START.QuestionWithAnswers
#Code
Layout = "~/Views/MedicalQuestions/MedicalQuestions.vbhtml"
End Code
<div id="questionPanel">
#Code
Dim qAndARef As Integer = 0
End Code
<!-- Show question text and number -->
<h1>Model.questionText</h1>
<table>
<tr>
<td style="font-weight: bold">
Beneficiary </td>
<td style="font-weight: bold">
Yes/No </td>
<td style="font-weight: bold">
Details </td>
</tr>
<!-- !!Iterating over each beneficiary for Medical Question -->
#For Each benanswer As RHEAL_START.BeneficiaryAnswer In Model.benAnswers
Html.Partial("../MedicalQuestions/BeneficiaryAnswerPartial", benanswer)
Next
</table>
#*#Html.ValidationSummary()*#
</div>
#Section Scripts
#Scripts.Render("~/Scripts/RHEAL/YesNoDropDownValidation.js")
End Section
I'm not that familiar with the VB syntax for Razor, but it looks like you're missing a # sign in front of #Model.questionText

How to add an HTML5 data-something attribute in Razor

I am trying to generate a table like this
#foreach (var item in #Model.Where(o => o.Status == "Submitted")){
<tr class="row" data_orderid="#item.Id">
<td class="description">
#item.Customer
</td>
<td class="description">
#item.OrderDescription
</td>
...etc...etc
so that I can handle the click event of each tr, and display some info based on the data-orderid attribute value of the tr that was clicked.
In Visual Studio I get a validation message saying "data_orderid is not a valid attribute of tr" and when it renders the HTML tr has no attributes, Not event the class.
How should I be adding attributes like this?
The format of HTML 5 data attribute is like this
data-AttributeName=AttributeValue
Example :
data-name="John Resig"
Change underscore to a hiphen and it will be rendered correctly.
<tr class="row" data-orderid="#item.Id">
First of all it is more likely that you should be using "data-xxx" (rather than "data_xxx") attributes.
Secondly, It is unlikely (if not imposible) for visual studio to omit class and your "data_orderid" attributes.
Make sure that for loop gets any elements from your condition #Model.Where(o => o.Status == "Submitted"
Additionally, as a note, Razor is smart enough to interpret 'html attributes' passed to elements, like here:
#Html.TextBoxFor(m => m.Name, new { #data_orderid = item.id, #class="input-xxlarge" }))

#Html.RenderPartial causing #Html.CheckBoxFor to uncheck values

I have a partial view that I'm currently rendering and everything loads up nicely. I also have a #Html.Checkboxfor that iterates through a collection of items and enables a check for the controller when the value is 'True'. My problem is that the #Html.RenderPartial() seems to be unchecking all the values once it loads. I've checked the model and the values are there, if I remove #Html.RenderPartial() for my partial view then the #Html.CheckBoxFor() will display the checked values.
I'd like to ask the SO community if there is a fix for something like this as I've tried other solutions, but nothing seems to work.
Thanks in advance!
<fieldset>
<legend>Organization Access</legend>
<table>
<tr>
#{Html.RenderPartial("_OrganizationAccess");}
</tr>
</table>
</fieldset>
<fieldset>
<legend>Alerts</legend>
<table>
#for (var i = 0; i < Model.AlertMembership.Count; i++)
{
<tr>
<td>#Html.CheckBoxFor(p => p.AlertMembership[i].AlertStatus)</td>
<td>#Html.LabelForModel(Model.AlertMembership[i].AlertName)</td>
<td>#Html.HiddenFor(p => p.AlertMembership[i].AlertId)</td>
</tr>
}
</table>
</fieldset>
Found out what the problem was partial view's when rendered using (#HtmlRenderPartial("view here")) will load not only the content, but also affect the other DOM objects/attributes on the view page. I traced the problem down to an issue where the inputs where being checked to false. This is why the #Html.CheckBoxFor was showing 'false" for the checked attribute after the partial view rendered.

Resources