Excel VBA to Deal With AJAX - 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

Related

Thymeleaf - Error displaying list/collection fields

I am converting a document that is readonly into a one where a user can edit.
Looping the values into a text was possible, my problem is converting those text into fields.
Currently I have the following code in my HTML, whereby the defectDto is the object I am planning on using to capture the fields.
<tr th:each="res, stat : *{response}" th:object="${defectDto}">
<td>
<input type="number" th:field="*{res[__${stat.index}__].defectId}" readonly="true"/>
</td>
...
</tr>
The HTML code above results in a processing error, please see image below:
In Java, I've used the model to bind the list returned (as seen below):
model.addAttribute("response", getDefectMessage.getMessage());
getDefectMessage.getMessage() above is of type List of DefectDto. The sample data is as seen below (please see image).
Being a newbie in Thymeleaf, may I please get assistance in rendering the HTML page without any errors. (Thanks in advance).

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"]

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.

Selenium click() or isSelected() are not executed on RadioButton's input element

I have radio buttons that are located inside a table, such as:
<tr id="radiofield-1080-inputRow">
<td class="x-form-item-body" id="radiofield-1080-bodyEl" colspan="3">
<input type="button" id="radiofield-1080-inputEl" class="x-form-field" autocomplete="off">
<label id="radiofield-1080-boxLabelEl" class="x-form-cb-label">My Label</label>
</td>
</tr>
I do find the input element, by the following code:
xPath = String.format("//tr/td[contains(#id,'%s')][contains(label,'%s')]/label", xType, text);
webElement = webDriver.findElement(By.xpath(xPath));
but isSelected() or click() doesn't seem to work on it.
Do you have any suggestion?
Haven't used selenium in a while but from a quick google it looks like you should try the isChecked and check/uncheck methods.
Here's the Javadoc but for some reason can't get a decent link, obviously check on the Selenium object. If you're using a different version or if I misunderstood something sorry.
http://selenium.googlecode.com/git/docs/api/java/index.html
In your code snippet problem with locator.
Use any of the below below locators
By.cssSelector("input[id*='radiofield-']");
By.id("radiofield-1080-inputEl")
By.xpath("//tr/td[contains(#id,'radiofield-')]/input")
Try clicking on the "input" instead of the "label".
xpath of input:
"//input[#id='radiofield-1080-inputEl']"
If the input id is not always the same, you can try this, the location of input will be based off the label:
//label[text()='My Label']/preceding-sibling::input
Thanks for all your answers.
My finding concluded with the following:
ExtJS implement radiobutton and checkbox as button, therefore the selenium isSelected() is not functioning.
There is a need to implement isSelected(), as suggested at:
How to check if extjs checkbox is selected in selenium?
The click() does the work, as it is a button.
Thanks again, Michal

Resources