Fetch data from extern HTML Table with javascript - javascript

I need to get data from a table in an EXTERNAL HTML file (on a different server) and store the data.
Is it possible to import a html file from a http URL to work with the data?
How can I read different rows and cols from external files?
I need to get the data, store it somehow (maybe JSON or an array?) so I can work with the data.
For Example:
<table id="table1" class="tg">
<tr>
<th>1A</th>
<th>1B</th>
<th>1C</th>
<th>1D</th>
</tr>
<tr>
<td>2A</td>
<td>2B</td>
<td>2C</td>
<td>2D</td>
</tr>
<tr>
<td>3A</td>
<td>3B</td>
<td>3C</td>
<td>3D</td>
</tr>
<tr>
<td>4A</td>
<td>4B</td>
<td>4C</td>
<td></td>
</tr>
<tr>
<td></td>
<td>5B</td>
<td>5C</td>
<td></td>
</tr>
<tr>
<td></td>
<td>6B</td>
<td></td>
<td></td>
</tr>
</table>
I Need to store the different colums like:
(1A,2A,3A,4A,)
(1B,2B,3B,4B,5B,6B)
(1C,2C,3C,4C)
(1D,2D,3D)
Thank you for your help :)

Related

How can I view my html page on browser like in printing preview

I have a html file with a table tag. This has a theader, tbody and tfooter.
The data in the table body are realy long. So I want that it splits when it's bigger then A4 size.
It works greate when I try to preview it for printing.
The data continue in a new page with header and footer from table.
Is there a way to show the same in my web browser?
My html file is something like that...
<table border="1">
<thead>
<tr>
<th>Anz Bezeichnung</th><th>Preis</th>
</tr>
</thead>
<tbody>
<tr>
<td>orange</td>
<td>20</td>
</tr>
<tr>
<td>orange</td>
<td>20</td>
</tr>
<tr>
<td>all the datas like this</td>
<td>20</td>
</tr>
</tbody>
For that you can use datatable which has inbuilt fuction for print.Check out DataTable.
for A4 size you can modify paging option

How to get selenium script to use a list for values?

I'm trying to create a selenium script to log into a site with a username and password complete a task, log out then start over but with a multiple different username/passwords. Is it possible to get the script to use values from a text file or something?
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/common/oauth2/authorize?client_id/td>
<td></td>
</tr>
<tr>
<td>assertTitle</td>
<td>Sign in to your account</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=cred_userid_inputtext</td>
<td>example#example.com</td>
</tr>
<tr>
<td>click</td>
<td>id=cred_password_inputtext</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=cred_password_inputtext</td>
<td>password1</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=cred_sign_in_button</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>css=span.ms-Icon--outlook</td>
<td></td>
</tr>
<tr>
<td>select</td>
<td>id=selTz</td>
<td>label=‎(UTC-08:00)‎ Pacific Time ‎(US & Canada)‎</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=span.signinTxt</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>xpath=(//button[#type='button'])[12]</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>xpath=(//button[#type='button'])[51]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//table[#id='use_another_account']/tbody/tr/td/table/tbody/tr[2]/td[2]/div</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
Sure it is possible to read from an external source and run your automation test.
If you have a lot of credentials, I would recommend that you directly talk to the test database to retreive that data and then use it for your automation test. I don't know javascript or python but I'm sure that if you Google, you can find a solution on how to do this.
If this is too complex, then you might just prefer to read from a file like a .csv. Python or javascript will probably have some frameworks that you can use to read .csv files. Worst case scenario is you will have to write your own logic to read the file, which I'm sure already exists on the web.
Whatever method you choose, just use your code to read that entity, store the values in variables, and then apply those variables in your tests. Here is a sample of my test using C#. It runs through many 'accessionNumbers' that it reads from an external source.
[Test, TestCaseSource("GetDataList")]
[Property("PBI#", "35656")]
public void GivenPopupItemIsOpen_WhenTogglingPopup_ThenPopupOpensAndCloses(string accessionNumber)
{
var studentAssesmentPage = OpenAdminResetPageAndGoToBookletLocation(accessionNumber);
studentAssesmentPage.ShortTextPopup.OpenPopUp();
studentAssesmentPage.ShortTextPopup.ClosePopUp();
Assert.IsFalse(studentAssesmentPage.ShortTextPopup.IsPopUpOpen(), "The pop up did not close after trying to close the pop up");
}

Is it possible to use jQuery and Django on the same page?

I'm trying to just a jQuery function to show a table on a Django page. When I test the script on jsfiddle, it works great but it's not working on my Django site. Do I need to import something into Django to make it work?
This is what I have thus far:
html file:
<table class="panel">
<tr>
<td colspan=3 class="tblheader"><h1>Statistics</h1></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<button class="spoiler">Click for Spoilers</button>
javascript file:
$(document).ready(function() {
$('.spoiler').click(function() {
$('.panel').slideToggle('slow');
});
});
You should add reference to jquery script from your Django html template, for example
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
More information on jquery site

Select row in HTML table to update chart selection?

How do I setup an HTML+JS table with data associated to a chart (Flotr or D3); where I can multiselect rows and that will update what is shown in the chart? - I'll likely be using AngularJS, so their two-way data-binding might be of help...
E.g.:
<table>
<thead>
<tr><th>Vowel</th> <th>Amount</th></tr>
<thead>
<tbody>
<tr> <td>A</td> <td>3</td> </tr>
<tr> <td>E</td> <td>6</td> </tr>
<tr> <td>I</td> <td>7</td> </tr>
<tr> <td>O</td> <td>8</td> </tr>
<tr> <td>U</td> <td>9</td> </tr>
</tbody>
</table>
Would also be great to be able to go reverse as well, e.g.: pressing E and A on the pie graph would refresh the pie-graph + the table.
http://plnkr.co/edit/x1jGW0lqKyzV7EKsVAbJ?p=preview
Here is the example of how you could do it.
Once you create an directive to connect your data with the DOM, then
it is simple matter of handling the data model through template.
I reused the flot integration directive that I used for other project.
(This 'reusability' is what I love about AngularJs.)

Selenium IDE replace string within stored variable

I'm trying to replace " characters within text stored within a Selenium IDE test.
As an example I'm doing
<tr>
<td>storeText</td>
<td>id=request-header</td>
<td>variable1</td>
</tr>
<tr>
<td>echo</td>
<td>javascript{'hi'.replace('i','a')}</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>javascript{$variable1.replace('G','a')}</td>
<td></td>
</tr>
The first echo outputs 'ha' but the second results in an error.
Thanks
In javascript execution context you have to use the storedVars array to access stored variables:
<tr>
<td>echo</td>
<td>javascript{storedVars.variable1.replace('G','a')}</td>
<td></td>
</tr>

Categories

Resources