Delete all HTML elements from page using Find and Replace with regex - visual-studio

I've got a large number of <asp:RequiredFieldValidator> server controls that I want to delete from multiple webforms pages. It's too tedious to remove them all by hand.
How can I create a regex to use in Visual Studio's Find and Replace dialog?
I'd like to remove the server control entirely. In the example below, it'd leave an empty table cell.
Currently
<td>
<asp:RequiredFieldValidator attr1=""></asp:RequiredFieldValidator>
</td>
Leaving only (whitespace not necessary to remove):
<td></td>

Related

Selenide - found and fill the element

I failed to allocate following element via selenide (i need find and fill it with text (ID) :
<tr>
<th class="col-md-3 basicPropertiesName">Id</th>
<td class="col-md-9">
<input class="form-control ng-pristine ng-valid ng- touched" ng-keypress="keypressHandler($event, 2)" ng-model="newInsight.id" placeholder="ID">
</td>
</tr>
Or maybe this?
$("input[ng-model='newInsight.id']").setValue(value);
Maybe you need something like this?
By(xpath("//input[#ng-model='newInsight.id']))
$(By.xPath("//tr[./th[text()='Id']]")).find("input").setValue("some text)
or without additional find()
$(By.xPath("//tr[./th[text()='Id']]//input")).setValue("some text)
You could use following options using css selectors also.
String str="th[class*='basicPropertiesName']";
SelenideElement element =$(str);
or
String str="th:contains('Id')";
SelenideElement element =$(str);
one important moment.. all from above would fail if your example is placed in iframe (i've faced with such issue last week).
required actions:
a) how to find out if <tr> is (or not) part of iframe >> locate your tr on page, right-click on it, and ensure that you have no View frame source
example of page Inspect with iframe
if No such - try examples from above...
if There is one - see below
b) how to switch into iframe
you have to findout frame name...
--- make r-click on object + Inspert
--- locate your <tr>
--- click on it into Inspect
--- in the bottom of Inspert you'd see whole tree till selected element
--- move to the top of tree and you'd see something like iframe#framenamehere
--- copy it
before seaching your element add line like:
WebDriverRunner.getWebDriver().switchTo().frame(here the value from
prev. steps without #);
and search for your <tr>
I suggest that you use the th text in your query, to better target the input element:
Selenide.$(Selectors.byXpath("//th[text()='Id']/following-sibling::td/input"));
Note: Better to assign a unique id to the input element (and to every element under test) to improve readability and maintenance of your code.

View component of MVC. Should I pre generate HTML tag elements in the Controller for the View?

I'am currently creating a MVC Java Web App with Struts2.
One element of my app is searching for some results via form. When the user submits the form an Action gets the necessary values from the database and populates a Map:
Map<Integer,List<String>> values = new HashMap<Integer,List<String>>();
Which has a list of column values for each row.
By Following this approach I can have generic JSP for displaying the results of any resultbox:
<s:div cssClass='resultContainer'
cssStyle=' min-height: 150px; max-height:%{header}px; overflow: auto; %{display}; '
theme="qxhtml">
<table id='resultTable'>
<tr id='tableHeader'>
<s:iterator value="headers">
<th><s:property /></th>
</s:iterator>
</tr>
<s:iterator value="values">
<tr class='results'>
<s:iterator value="value">
<td><s:property escape="false" /></td>
</s:iterator>
</tr>
</s:iterator>
</table>
I feel now that this is a bad approach. Instead I should change the Map to a List of ResultBoxRow objects. Each ResultBox will have its own View Jsp instead of one generic one allowing me to iterate over the objects and output for example:
<s:iterator value="value">
<td><s:property name="firstname" /></td>
<td><s:property name="lastname" /></td>
etc.
In the case of the table headers I may need to give certain headers individual style properties. I feel these should be defined in the JSP itself rather than get the JSP to reference a value from the controller containing the style for that header.
I think my overall question is how much should the controller control the style/display of elements of the View? I feel it should just generate the individual elements displayed in the tags but not the values to put in the "style" tag of the row for example. Even if this does sacrifice a simple single JSP to handle every result box.
It would be great to get your opinions.
The controller should have nothing to do with the display mechanism: that's the point of MVC, to completely separate the data from its presentation.
You can still DRY up the view layer via custom tags, includes, templates, etc. Styles may be passed as attributes, while the underlying DOM would be created by a single page or template.
It also matters what the nature of the attributes you want to pass. If they're semantic that could logically from from the model or controller that's fine. If they're purely presentational, like colors, widths, etc. then it has no business in the model or controller.

How can I use selenium to drop in a specific place?

I am trying to write a selenium test for a drag and drop operation.
I am dropping in a tr but I need to specify whereabouts on the row as the tr itself covers 5 slots (this is for a calendar app) but the slots are not td's so I think the app might be using some sort of x,y co-ordinates within the tr.
Specifically the tr that goes all the way across is
<tr class="fc-slot15 fc-minor">
<th class="fc-agenda-axis fc-widget-header"></th>
<td class="fc-widget-content">
<div style="position:relative"></div>
</td>
</tr>
So far the best xpath I have is xpath=(//table//tr[contains(#class,'fc-slot15')]//td) but this identifies the whole tr.
Visually it looks like this:
I'm trying to do it for full-calendar but how to drop in a specified place seems general enough.
Could I do it with mouse down, mouse move(x,y), mouse up perhaps?

MVC3 Razor Table loading outside of Span/Div/P

I am having a problem where I try to render a <table> inside of parent container, but MVC3 Razor always renders the outside of the container tag. This causes problems when trying to control the outside parent container via Javascript.
Razor Example:
<span id="mySpan">
#Html.Action("Table1", "GetMyTable")
</span>
HTML that is output:
<span id="mySpan"></span>
<table>
<thead><tr><th>Header</th></tr></thead>
<tbody>
<tr><td>Foo</td></tr>
<tr><td>Bar</td></tr>
</tbody>
</table>
No matter which parent container I try to stick the table into, a div, span, p, the table always renders OUTSIDE the container's tags! Can anyone explain what I am doing wrong? How should I code the Razor syntax to properly add the table inside those tags?
as you are viewing the output in Firebug, what is happening is you are seeing an "effective" view of the html, after the browser engine has parsed it.
in HTML5, many tags do not need to be explicitly closed. If you include a tag "inside" another that is invalid (like a table inside a span), the browser assumes what you are doing is using an unclosed span tag, so it automatically closes it for you before starting the table tag.
The easiest fix here would be either not to "wrap" the table, or wrap it with something that HTML5 considers valid, such as a section tag.
Another option would be going back to XHTML1.1, where a table is valid inside a div (but not inside a span). Also, XHTML requires explicit closing tags, so this behavior would not show up there. (the same thing for XHTML5, though it's still invalid to wrap a table with a div in XHTML5)
Viewing the raw source would reveal that Razor is not axtually changing anything here; it is the browser. It is good to see this, though; so you know what the browser is expecting and how it's handling what you are sending it.

manage jquery tables with watin

I am using Watin with Cucumber and Specflow to automate the testing of a web application using a jquery table.
I want to find a specific data in the table, but i don't know how to access the table. When I find the data i am looking for, i want to return the id of the row to pass it to an URL that navigate to the Delete page so I can delete the data.
This is my code in the page:
<tr id="S-1-5-21-373314506-2757628719-1954316189-3686" class="ui-widget-content jqgrow ui-row-ltr" role="row" tabindex="-1">
<td class="ui-state-default jqgrid-rownum" aria-describedby="list_rn" title="2" style="text-align:center;" role="gridcell">2</td>
<td aria-describedby="list_Actions" title="Edit | Details | Delete" style="" role="gridcell">
Edit
|
Details
|
Delete
Ivana Bagur
So, in this example, I want to go through my table and when i find Ivana Bagur, return the tr id attribute so then I can pass this id attribute to effectively delete the element.
Can anyone give me an idea how to go through the table until i find the data and then capture the tr id?
First, something is off in the code you posted as it is not showing entirely correctly; somehow you got actual links to display starting at 'details' rather than your code.
To find the TR ID....general idea:
Find the element containing Ivana Bagur
Find the ancestor of that element that is a TR.
If Ivana is just text in a tablcell it might look like:
string IvanaRowID = ((TableRow)(myIE.Table(myID).tablecell(Find.ByText(myRegexContainingIvanaBagur)).Ancestor("tr"))).Id;
It has been a while since I've done this, and my casting might be a bit off / non-optimal, but the general idea is there.

Resources