Select table in Mechanize (ruby) - 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.

Related

Excel VBA to Deal With AJAX

I am practicing to use excel vba to download information from website: http://mops.twse.com.tw/mops/web/t05sr01_1
But I have no idea how to download the data behind click button, as the image shown: http://i.stack.imgur.com/KZHiZ.jpg
I excerpt its web code as below. Could anyone explain me how to code in excel vba to get its data?
Thank you very mush.
Web code:
<td style='text-align:left !important;' nowrap>鴻海</td>
<td style='text-align:left !important;'>105/01/05</td>
<td style='text-align:left !important;'>11:41:00</td>
<td style='text-align:left !important;'>說明媒體報導</td>
<td><input type='button' value='詳細資料' onclick="document.fm_t05sr01_1.SEQ_NO.value='1';document.fm_t05sr01_1.SPOKE_TIME.value='114100';document.fm_t05sr01_1.SPOKE_DATE.value='20160105';document.fm_t05sr01_1.COMPANY_NAME.value='?E??';document.fm_t05sr01_1.COMPANY_ID.value='2317';document.fm_t05sr01_1.skey.value='2317201601051';document.fm_t05sr01_1.hhc_co_name.value='?E??';ajax1(this.form,'table01');">
You haven't shown how you are getting the html.
You can use a CSS selector.
General for first input button
input[type=button]
This says element(s) with input tag having attribute type whole value is 'button'
You apply with the querySelector method, or querySelectorAll if more than one match and then use index for required element.
ie.document.querySelector("input[type=button]").Click
If in an HTMLDocument variable e.g. htmlDoc then
htmlDoc.querySelector("input[type=button]").Click

Dandelion Datatables + Thymleaf + dt:format

I've tried to implement the formatting attribute for Dandelion Datatables as specified here using Thymeleaf to no avail, like so:
<table dt:table="true" dt:serverside="true" dt:url="#{/somefnplace}">
<thead>
<tr>
<th dt:property="someCurrencyField" dt:format="{0, number, #.##}">
</tr>
</thead>
</table>
...but this does not do anything. Anyone got an idea on how this is supposed to work, or do I have to create render functions for every column because this feature is broken?
Unfortunately, the dt:format attribute is not compatible with AJAX sources. See the last column of the link you've mentioned.
In the upcoming version, it will simply be removed, because using DOM sources, expression utility objects meet all needs perfectly.
So yes, currently the only way is to use the dt:renderFunction attribute, which will refer to a rendering function, one for each column to need to display in a specific format.

using xpath to find Href in selenium webdriver

i have to find the following href using selenium in java
<tr>
<td>
<a target="mainFrame" href="reb.php?tiEx=ES"></a>
</td>
</tr>
thanks
There are multiple ways to find the link depending on the elements it is inside and the uniqueness of the element attribute values on the page, but, from what you've provided, you can rely on the target attribute:
//a[#target="mainFrame"]
You can also narrow it down to the scope of it's parents:
//tr/td/a[#target="mainFrame"]
Also, you can additionally check the href attribute if it is persistent and reliable:
//tr/td/a[#target="mainFrame" and #href="reb.php?tiEx=ES"]

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.

Xpath query to find elements which contain a certain descendant

I'm using Html Agility Pack to run xpath queries on a web page. I want to find the rows in a table which contain a certain interesting element. In the example below, I want to fetch the second row.
<table name="important">
<tr>
<td>Stuff I'm NOT interested in</td>
</tr>
<tr>
<td>Stuff I'm interested in</td>
<td><interestingtag/></td>
<td>More stuff I'm interested in</td>
</tr>
<tr>
<td>Stuff I'm NOT interested in</td>
</tr>
<tr>
<td>Stuff I'm NOT interested in</td>
</tr>
</table>
I'm looking to do something like this:
//table[#name='important']/tr[has a descendant named interestingtag]
Except with valid xpath syntax. ;-)
I suppose I could just find the interesting element itself and then work my way up the parent chain from the node that's returned, but it seemed like there ought to be a way to do this in one step and I'm just being dense.
"has a descendant named interestintag" is spelled .//interestintag in XPath, so the expression you are looking for is:
//table[#name='important']/tr[.//interestingtag]
Actually, you need to look for a descendant, not a child:
//table[#name='important']/tr[descendant::interestingtag]
I know this isn't what the OP was asking, but if you wanted to find an element that had a descendant with a particular attribute, you could do something like this:
//table[#name='important']/tr[.//*[#attr='value']]
I know it is a late answer but why not going the other way around. Finding all <interestingtag/> tags and then select the parent <tr> tag.
//interestingtag/ancestor::tr

Resources