Extract information from web page throughExcel vba - html

I have the following html code
<tr>
<td class="fontblue" style="height: 17px">
Primary Industry Code
</td>
<td class="fontlightblue" style="height: 17px" colspan="4">
<span id="ucOrganisationDetail_lblVPrimarySector">
FMP CB:Miscellaneous Manufacturing
</span>
</td>
</tr>
I would like to extract the text FMP-CB Miscellaneous Manufacturing using getelementbyID option in vba. can anyone please help me
I tried using the below vba code but nothing is working
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").Value

Try the following:
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").innerHTML

You want .innerText as mentioned in comments I see.
.innerText
Sets or returns a String that represents the text between the start
and end tags of a specified object without any associated HTML.
expression.innerText
expression Required. An expression that returns one of the objects
in the Applies To list.
You could use
objIE.Document.getElementById("ucOrganisationDetail_lblVPrimarySector").innerText
or a CSS selector which says the same thing of:
objIE.Document.querySelector("#ucOrganisationDetail_lblVPrimarySector").innerText
The element is correctly selected as you can see with:

Related

Robot Framework: How to get xpath of an element?

I am trying to retrieve the id of a parent (grand-grand-parent) element.
All the information I have is that //div[#class="preset_name"] is "all". Knowing that, I need to retrieve "preset_3" (as a string) using any of the Robot Framework keywords.
How would I do that? Or how can I obtain the full xpath of "all"?
<table id="preset_list">
<tbody>
<tr id="preset_0">
<td>
<div class="preset_title_line">
<div class="preset_button_group">
<button class="preset_button">Apply</button>
</div>
<div class="preset_name">Factory default</div>
</div>
<div class="preset_sections">System, Network, Sources, EDID, Channels, Automatic File Upload, Touch screen, Output ports</div>
</td>
</tr>
<tr id="preset_1">
<td>
...
You can filter tr that contains //div[#class="preset_name"] = "all", and then return the corresponding id attribute :
//tr[.//div[#class='present_name'] = 'all']/#id
Your XPath should be:
Get Element Attribute xpath=(//div[#class="preset_name"][text()='all']/../../..)#id
(I've never used Robot, but I think it is the correct sintax)
Its easy if you are using "relative xpath helper chrome extension".
https://www.linkedin.com/pulse/finding-relative-xpath-made-easy-syam-sasi?trk=prof-post

optimize angularjs search filter and trigger html tab even by clicking on link

I hope someone can help me with these two problems.
They are part of the same work but different from each other.
I am using angularjs to filter through a list that is quiete big (more than 1000 elements) but it's very slow. I was wondering if there's a way to optimize this.
Here's the code
<div class="test">
<table class="table table-hover" >
<tbody>
<tr ng-repeat="test in tests| filter:query">
<td>
<div id="delete">D<br />E<br />L<br /></div>
<div id="edit">E<br />D<br />I<br />T</div>
<p ng-show="test.id">ID:<b>{{test.id}}</b></p>
<span ng-repeat="name in test.names" ng-show="test.names">Company: <b>{{name}}</b></span>
<span ng-repeat="age in test.ages" ng-show="test.ages">Country: <b>{{age}}</b></span>
<span ng-repeat="course in test.courses" ng-show="test.courses">Found: <b>{{course}}</b></span>
<span id="output" ng-show="test.out1">Then: <b>{{test.out1}}{{test.out2}}{{test.out3}}{{test.out4}}</b></span>
</td>
</tr>
</tbody>
</table>
</div>
The second question is regarding "tabset" in html
I have 3 tabs and in one tab I have an edit link on each item, I want the third tab to come up when I click on the edit link of the first tab.
I searched online and understand that some js or jquery is needed but nothing has worked so far.
thank you in advance
If you are handling such a big set of data you should use a pagination system.
Also I won't attach the entire 1k object to the scope and and use a filter in the ng-repeat but instead add just a chunk of data like 50 to the scope and every time you change the page you would change the $scope.tests with the next/previous 50 items from your 1k.
One more point, if you are using a lot of interpolation {{}} but not each of them needs a separate watcher you should consider using angular's "bindonce".

CKEditor - how to save and display html code in rich text

I had html textarea's with plain text, there are html code samples stored in MySQL.
I changed textarea's to ckeditor class. All is fine, but all html code blocks are not displayed now in rich text mode.
I've tried to use <pre> and <code> tags, but they are don't work.
Also I tried insertpre plugin, and it doesn't help.
Is there a way to display/save html code in CKEditor? How to ignore html tags in the block like on this site with Code Sample button?
My example.(Sorry, have no permissions to post images yet).
Textarea field:
<textarea class="ckeditor" name = "description" >Text</textarea>
I'm pasting code using "Insertpre" addon:
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
At once I see correct picture.
After form submit I get variable:
$description=$_POST['description']; and put it to database.
In database I see next value for this variable:
<pre class="prettyprint">
<table border="1">
<tr>
<td>100</td>
</tr>
</table></pre>
html form which displays data from base:
<textarea class="ckeditor" name = "description" ><?php echo $description ?></textarea>
When I open this form, I see empty code block, all html code is outside of pre-block, and I see a real table instead of html tags.
If I click on “Source” button , I see the same – table tags are not inside “pre” tags:
<pre class="prettyprint">
</pre>
<table border="1">
<tbody>
<tr>
<td>100</td>
</tr>
</tbody>
</table>
As I understand, code saved in database in correct format, so problem somewhere in the output or in CKEditor behavior...
Update: Found workaround:
After long search I found similar problem in this topic: http://ckeditor.com/forums/CKEditor-3.x/html-code-pre-tags-problem
Described workaround helped me: if I make output with htmlspecialchars php function it works good:
<textarea class="ckeditor" name = "description" ><?php echo htmlspecialchars($description) ?></textarea>
I'm not sure is it a workaround or correct solution - after this all tags inserted in rich mode are displayed even without "pre" block. If yes - it should be in CKEditor FAQ, because this is very confusing.
May be I'm late. But it will be good to share a solution that worked for me for the same problem so it might help someone.
I was having a similar problem with ckeditor, I saved the user inputs in my table and when I wanted to display the saved html in ckeditor instance it would simply ignore the html and display nothing.
So I inspected the html on my console and found that it has \r\n. So I just removed them and when I served it back to the ckeditor after escaping the html, it worked.
Here is my ruby code:
html = "<p>Content comes here</p>\r\n"
In my view
CKEDITOR.instaces.my_editor.setData("#{raw(html.gsub('\r\n',''))}")
And it worked. Hope that helps.

Find the XPATH for a table of data

I'm trying to learn about scraping information from a website for iOS and I'm using a website of a local radio station to practice. I have tried by best to figure out the Xpath needed to present the information within the tags in a table. The HTML is as follows (there are many more table rows, this is just the first one).
EDIT
<form action="http://www.someurl.ie/index.php/news" method="post" name="adminForm" id="adminForm">
<table class="category">
<tbody>
<tr class="cat-list-row0" >
<td class="list-title">
<a href="/index.php/news/some-news-story-here">
some news story here</a>
</td>
</tr>
This is the path that I have come up with but it hasn't worked for me. Could anyone direct me as to what I'm doing wrong/missing with this?
#"//div[#class='cat-items']/form[#id=adminForm]/#action/table[#class='category']/tbody/tr[#class='cat-list-row']/td[#class='list-title']/a"])
<div class="cat-items">
If anyone could help or point me in the direction of help I would be very grateful. Thanks!
There are three problems in your XPath expression:
The <form/> id 'adminForm' is unquoted
The attribute #action is a path step in the middle of the expression
The <tr/> class 'cat-list-row0' is missing the zero.
The corrected expression:
#"//div[#class='cat-items']/form[#id='adminForm']/table[#class='category']/tbody/tr[#class='cat-list-row0']/td[#class='list-title']/a"

using xpath axes correctly to locate

I am testing a web page with dynamic ids. The page contains a remove icon followed by a browse icon at multiple places and I am not able to click these icons or I must say I am not able to write the correct XPath to locate any particular icon.
The following is a snippet of the HTML code.
<tr class="tableNestedAttribute">
<td class="autosuggest-svl-cell">
<input name="odf_obs_fin_dept_text">
<div id="div_d31505e760_location"></div>
</td>
<td class="actions" nowrap="" align="right">
<div class="ui-browse-lookup-images ppm_field formFieldDisNoWidthReadOnly ">
<img id="d31505e7601" title="Remove Department OBS" name="Remove">
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
</div>
</td>
</tr>
The above HTML code is at multiple places in the page except that the name in the first td is different at each place.
My requirement is here to click the browse which is in the same line as the input field with name odf_obs_fin_dept_text.
Tried the following and various other combinations but with no luck.
driver.findElement(By.xpath("//*[#name='odf_obs_fin_dept_text']/following-sibling::td[1]/descendant::div/img[#name='Browse']")).click();
With the provided example the following XPath:
//input[#name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/div/img[#name='Browse']
will find the next element:
<img id="d31505e7600" title="Browse Department OBS" name="Browse">
Or if you want to keep your XPath intact, only add parent::td between //*[#name='odf_obs_fin_dept_text'] and following-sibling::td[1]
//*[#name='odf_obs_fin_dept_text']/parent::td/following-sibling::td[1]/descendant::div/img[#name='Browse']