manage jquery tables with watin - 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.

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.

Select table in Mechanize (ruby)

I try with my internet-bot to get infos from a table on a website.
The table has just "map_table" as id (CSS attribute) tr has "map_tr" and for a cell it's "map_td".
I want to detect the cells with a link containing "msg.php" in their href.
Ex :
<td id="map_td">
</td>
This one has not to be selected
<td id="map_td">
</td>
This one has to be selected. I have searched in the Mechanize doc, in forums, I haven't found anything.
Can you help me ?
That should be:
page.search('td:has(a[href*="msg.php"])')
It's the Nokogiri docs that you want look at, but really, the CSS or XPath specs if you're not familiar with either of them.

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

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>

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?

Selenium WebDriver and xpath: a more complicated selection

So let's say my structure looks like this at some point:
..........
<td>
[...]
<input value="abcabc">
[...]
</td>
[...]
<td></td>
[...]
<td>
<input id="booboobooboo01">
<div></div> <=======I want to click this!
</td>
.........
I need to click that div, but I need to be sure it's on the same line as the td containing the input with value="abcabc". I also know that the div I need to click (which doesn't have id or any other relevant attribute I can use) is in a td at the same level as the first td, right after the input with id CONTAINING "boo" (dynamically generated, I only know the root part of the id). td's contain nothing relevant I can use.
This is what I tried as far as xpath goes:
//input[#value='abcabc']/../td/input[contains(#id,'boo')]/following-sibling::div
//input[#value='abcabc']/..//td/input[contains(#id,'boo')]/following-sibling::div
None of them worked, of course (element cannot be found).
I want to know if there's a way of selecting that div and how.
EDIT: //input[#value='abcabc']/../../td/input[contains(#id,'boo')]/following-sibling::div is the correct way. This was suggested by the person with the accepted answer. Also note that he offered a slightly different way of doing it. See his answer for details.
Try
//input[#value='abcabc']/ancestor::tr[1]/td/input[contains(#id,'boo')]/following-sibling::div[1]
Note that //input[#value='abcabc']/.. only goes up to the parent <td>, that's why your's did not work.
Another XPath that may work, is a bit more simple:
//input[#id='booboobooboo01']/../div[1]

Resources