Excel VBA Extract Value from Web Site and Insert in Excel - vba

I'm trying to pull the "Available Balance" dollar amount from a web site and have the amount entered into my Excel sheet. Below is the code section from the web site and the page source is located here, http://pastebin.com/VsThEzEE. Thanks in advance for any suggestions.
<table class="bd-wizard-account-header">
<tr>
<td valign="bottom"><img src="/Content/images/tenants/visaUS/en-us/vgCard1.png" /></td>
<td valign="bottom"><h6>Card Ending</h6><h5>0102</h5></td>
<td valign="bottom"><h6>Available Balance</h6><h5>$0.00</h5></td>
<td valign="bottom"><h6>Initial Balance</h6><h5>$300.00</h5></td>
</tr>
</table>

After more searching, I was able to pull the info that I needed and enter it into my Excel sheet with the following.
Dim dd As String
dd = IE.Document.getElementsByTagName("h5")(1).innerText
ActiveCell.Value = dd

It is also the third td tag within the element with className "bd-wizard-account-header" with the tag table
Without knowing how many tables there are you could use the equivalent CSS selector, as described above, of:
table.bd-wizard-account-header td:nth-child(3)
or potentially just
.bd-wizard-account-header td:nth-child(3)
CSS selector query on HTML supplied:
Reference material:
CSS Class selector
nth-Child
VBA:
You can apply the selector via the .querySelector method of the IE.Document. .querySelectorAll if table/class index is greater than 0 i.e. there are more than one the page and the one you require is not the first.
Example syntax:
IE.Document.querySelector("table.bd-wizard-account-header td:nth-child(3)").innerText

Related

Unable to find correct Target selector to click an element

Please see the image below which shows code of the web page in Developer Tools window and advise me the correct selector for 'Depreciation Models'. Text highlighted in red is constant, however the surrounding text is dynamic. So I tried using contains selector to locate but unsuccessful. I want to avoid XPATH as number of before and after div elements may keep changing.
I am using Selenium IDE hence the C#/Java code for RC/Webdriver won't help much.
Selenium IDE generated target path is this:
css=#dhxId_rgWATog7lC3E_27572|6059|6152 > td.sub_item_text > div.sub_item_text
I tried
css=contains('27572') > td.sub_item_text > div.sub_item_text
but it didn't work.
Kindly suggest. I am stuck. Thanks.
As you tried the Locator Strategy as :
css=contains('27572') > td.sub_item_text > div.sub_item_text
Reasons for not working
From the snapshot of the HTML you have provided, 27572 is not the innerText but partial string of the id attribute.
As per selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”:
The :contains pseudo-class isn't in the CSS Spec and is not supported by either Firefox or Chrome (even outside WebDriver).
Solution
You can use the following xpath as per the existing DOM Tree:
xpath=//tr[#class='sub_item'][contains(#id,'27572')]//td[#class='sub_item_text']/div[#class='sub_item_text'][contains(.,'Depreciations Models')]
I guess this would be the right approach:
<style>
[id*="27572"] > td.sub_item_text > div.sub_item_text{
color:red;
}
<table>
<tbody>
<tr id="dhxId_rgWATog7lC3E_27572|6059|6152" class="sub_item">
<td class="sub_item_icon">
<i class="fa fa-user epc-down-circled-2"></i>
</td>
<td class="sub_item_text">
<div class="sub_item_text"> Depriciations Models</div>
</td>
</tr>
</tbody>
</table>
It will set all elements that have an id attribute value containing "27572" and inside of it.

How to select the drop-down items which is out of tag using xpath

I've tried several xpath's for choosing the dropdown list. But nothing is worked.
Some of the xpath's I used are as follows:
By.xpath("//table/tbody/tr[2]/td[2]/span").click;
Or
By.xpath("/td[2]/span[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;
Please find the below html tags, I need to select the value either 'ASYLUM SEEKER PERMIT DOCUMENT' or 'NATIONAL IDENTITY DOCUMENT'.
<tbody>
<tr id="jP2Qrg" class="z-comboitem">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
<span class="z-comboitem-spacer"/>
ASYLUM SEEKER PERMIT DOCUMENT
</td>
</tr>
<tr id="jP2Qsg" class="z-comboitem z-comboitem-over">
<td class="z-comboitem-img"/>
<td class="z-comboitem-text">
<span class="z-comboitem-spacer"/>
NATIONAL IDENTITY DOCUMENT
</td>
</tr>
</tbody>
When I try to take xpath using firepath, it is dynamic. Every time the xpath and the id is keep changing. So please suggest the xpath which works.
The text is not inside the span text and it is in second td tag. you can try with small change in your code as given below.
By.xpath("//table/tbody/tr[2]/td[2]").click;
or
By.xpath("//td[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;
Can you check this..,
By.xpath("//*[contains(text(),'NATIONAL IDENTITY DOCUMENT')]").click;
By.xpath("//*[contains(text(),'ASYLUM SEEKER PERMIT DOCUMENT')]").click;
Try to use below XPath to match required option:
By.xpath("//td[normalize-space()='ASYLUM SEEKER PERMIT DOCUMENT']").click;
or
By.xpath("//td[.='ASYLUM SEEKER PERMIT DOCUMENT']").click;
As #Murthi said, text node is not a child of span, but td. Note that there are some specifics in locating text nodes
Here is the Answer to your Question:
To click on ASYLUM SEEKER PERMIT DOCUMENT you can use the following xpath:
By.xpath("//td[contains(.,'ASYLUM SEEKER PERMIT DOCUMENT') and not (#class='z-comboitem-spacer')]").click;
Let me know if this Answers your Question.
How about this xpaths,
Updated code
(//td[2])[1]//*[starts-with(#class,"z-com")]; // Selects ASYLUM..
(//td[2])[2]//*[starts-with(#class,"z-com")]; // Selects NATIONAL..
This should work if it doesn't have same class name in the same position.
Old xpath's
driver.findelement(By.xpath("(//td[2])[1]")); // selects ASYLUM SEEKER PERMIT DOCUMENT
driver.findelement(By.xpath("(//td[2])[2]")); // selects NATIONAL IDENTITY DOCUMENT
Find out the solution for selecting the dropdown options.
By using List method, I took the list of options available in that field and selected by using clicking the index value of list.
List<WebElement> Idtype = driver.findElements(By.xpath("//tr[2]/td[2][#class = 'z-comboitem-text']"));
Idtype.get(0).click();

Bootstrap X-editable Table popup not correctly positioned when data-editable-type = "number"

I have this fiddle and you can see that when you input any value for price field , It's popup tip is not positioned on the text because its data type is number as when you input values for Names.
https://jsfiddle.net/6da007fm/21/
HTML
<table data-toggle="table"
data-editable-emptytext="This field is empty"
data-id-field="id"
data-url="/gh/get/response.json/wenzhixin/bootstrap-table/tree/master/docs/data/data2/">
<thead>
<tr>
<th data-field="name" data-editable="true" >Name</th>
<th data-field="price" data-editable="true" data-editable-emptytext="For free." data-editable-type="number" data-editable-placeholder="Enter a Number">Price</th>
JS
$.fn.editable.defaults.mode = 'popup';
Is it a normal behavior or there is any workaround to this. I am using this in my project web page and it has 5 columns in one row and is not looking very neat because of this.
-Thanks
you just need to override popovers core css
.popover{
left:190px!important
}
here is your updated fiddle Working demo

How can I insert a HTML tag before its parent tag using the Transformer from Genshi?

I need to modify the file table in my trac browser view by creating a class which implements the ITemplateStreamfilter class. I tried using the Transformer from genshi.filters.transform. My table looks like
<tbody>
<tr class="even">
<td class="name">
<a class="partent" title="Parent Directory" ..>..</a>
</td>
..
</tr>
..
</tbody>
I now need to insert a </td> tag just before the frist cell in the first row of the table. The problem is that I only can identify the position of column where I want to put the new cell befor by searching for the "Parent Directory" title: Transformer('//*[#title="Parent Directory"]'). How can I step one tag up than put the new cell before the first <td class="name"> tag?
I'm not THAT familiar with the support for XPATH of Transformer BUT:
What about
Transformer('(//td[*[#title="Parent Directory"]])[1]') and then using the before method?
As far as I understand, this should select the first td node with a child node with an attribute title="Parent Directory".
If you want to select any td with that kind of child node use
Transformer('//td[*[#title="Parent Directory"]]')
However, this only works if Transformer supports those XPATH expressions.
Edit 1
If you're sure, your td has an attribute class="name" you can also use Transformer('(//td[class="name" and *[#title="Parent Directory"]])[1]')

Handling of dynamic ids through selenium webdriver

Automate an application through selenium where id changes dynamically.how can i handle this.Pls help me..
HTML code is:-
<table border="0" cellpadding="0" cellspacing="0" width="1000px">
<tbody><tr id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_trSelectedQuote_0">
<td align="center" valign="middle" width="12%">
<input id="ctl00_ctl00_MainContent_CarQuoteMainContent_rpQuotes_chkCompare_0" name="ctl00$ctl00$MainContent$CarQuoteMainContent$rpQuotes$ctl00$chkCompare" type="checkbox">
</td>
In both the cases ( and ), I assume that the first part of the ID is unique. So you can use something like this.
//tr[contains(#id,'ctl00_')] and for input field //input[contains(#id,'ctl00_')].
Those don't look like dynamic IDs, but rather non-content-specific row IDs for elements in a list.
If that's the case, you can't immediately ascertain 'This row element is displaying data for MyCarQuotes.com' from this information alone as there's nothing in the HTML shown to base that query on.
If there's something in the rows you can use to 'identify' the content (eg a company name) - and you have a specific 'thing' you want to interact with - you could encapsulate the lookup and do something like
CheckboxForQuoteFromCompany("MyCarQuotes.com").Click();
If you're able to post more of the HTML (at least a full row), and more importantly the intention of your test, we may be able to be of more help.