How to find xpath from javascript href - selenium-webdriver

The scenario is I need to check all the by default elements present on a web page. I am trying to check the headers available on a web table.
I am able to find all headers except one whose name is IP Address / Host Name
<div id="ctl00_ContentPlaceHolder1_RadGrid1_GridHeader" class="rgHeaderDiv" style="overflow: hidden;">
<table id="ctl00_ContentPlaceHolder1_RadGrid1_ctl00_Header" class="rgMasterTable rgClipCells rgClipCells" style="border-color:#6788BE;border-width:1px;border-style:solid;width:100%;table-layout:fixed;overflow:hidden;empty-cells:show;">
<colgroup>
<thead>
<tr>
<th class="rgHeader rgSorted" style="font-weight:bold;font-style:normal;text-decoration:none;text-align:left;" scope="col">
IP Address / Host Name
<input class="rgSortAsc" type="button" title="Sorted asc" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl02$ctl01$ctl06','')" value=" " name="ctl00$ContentPlaceHolder1$RadGrid1$ctl00$ctl02$ctl01$ctl06">
</th>
</tr>
</thead>
<tbody style="display:none;">
</table>
</div>
I tried finding using below codes but failed to do so.
driver.findElement(By.xpath("//div[#id='ctl00_ContentPlaceHolder1_RadGrid1_GridHeader']//a[contains(#href,'IP Address / Host Name')]"));
driver.findElement(By.xpath("//a[contains(#href,'IP Address')]"));
driver.findElement(By.linkText(IP Address / Host Name));
I tried with changing div id and its value ti table id and corresponding value too but script fail saying not able to find element with xpath...
My script always says failed to find element with id... or xpath...
Please help.

If you're having trouble accessing the element programmatically, my advice would be to use the Selenium IDE to select the element, then export the test case by going to File > Export Test Case As... > Java / JUnit 4 / WebDriver.
I tried this myself and the resulting code uses:
driver.findElement(By.linkText("IP Address / Host Name"))
It seems to work fine in the Selenium IDE. I haven't tested the resulting Java code. - From your syntax, it appears you're using Java.
You say you've tried using By.linkText(), so maybe there's a bigger problem? (I notice you don't have quotes around your By.linkText() example, but I assume this is a typo.)

Related

How to verify the value of the data-qtip of button?

I'm making an automated test on IE8, and i need to verify the hint of a button, the site I'm automating uses extjs, and for some reason, IE8 and Selenium IDE with the IEDriver don't work very well when it comes to the command "mouseOver". I did the following on Selenium IDE in Firefox and it worked:
<tr>
<td>mouseOver</td>
<td>//span[text()='Relatórios de Retorno']</td>
<td></td>
</tr>
<tr>
<td>waitForVisible</td>
<td>id=ext-quicktips-tip-innerCt</td>
<td></td>
</tr>
<tr>
<td>verifyText</td>
<td>id=ext-quicktips-tip-innerCt</td>
<td>Gera relatórios de retorno</td>
</tr>
But it doesn't work on IE for some reason, even if i stop the Selenium IDE and the driver, and go "manually" with the mouse over the button, the hint don't popup, so i was thinking in try to verify it directly by the data-qtip, but i don't know how.Here's the button code i took with the F12 on IE8, i want to verify the value of the data-tip:
<A aria-disabled=false aria-hidden=false hideFocus style="MARGIN: 0px; TOP: 0px; LEFT: 495px" id=aejs-button-1104 class="x-btn x-unselectable x-box-item x-toolbar-item x-btn-default-toolbar-medium" role=button tabIndex=-1 unselectable="on" data-componentid="aejs-button-1104" data-qtip="Gera relatórios de retorno">
I found the solution with the command "verifyAttribute", here's how i did it:
<tr>
<td>verifyAttribute</td>
<td>id=aejs-button-1104#data-qtip</td>
<td>Gera relatórios de retorno</td>
</tr>

ng-show > 10 throws syntax error (VS browser link)

I have a table cell that shows if there's more than 10 records. Part of my pagination.
<td ng-show="totalRecords>10" colspan="5">
<ul uib-pagination style="margin:0;" total-items="totalRecords" ng-model="currentPage" ng-change="pageChanged()"></ul>
</td>
Pretty straightforward. But here's the crazy - it throws the following error in Chrome:
Uncaught Error: Syntax error, unrecognized expression: td[ng-show='totalRecords # browserLink:37
bc.error # browserLink:37
bh # browserLink:37
bp # browserLink:37
...etc
I'll note that $scope.totalRecords is set to zero (0) in the controller. Setting it to other values doesn't change anything. Everything else in the controller works perfectly.
The following scenarios don't throw any error:
<td ng-show="totalRecords=10" colspan="5">...</td>
<td ng-show="totalRecords<10" colspan="5">...</td>
<td ng-show="totalRecords>9" colspan="5">...</td>
<td ng-show="totalRecords>=11" colspan="5">...</td>
<td ng-show="totalRecords" colspan="5">...</td>
Anyone have a guess as to why?
The problem is with Visual Studio's "browser link" feature which can cause problems with AngularJS. Based on some research I did about the error you are experiencing, it seems that people are recommending to disable the browser link feature in Visual Studio.
http://connect.microsoft.com/VisualStudio/feedbackdetail/view/814546/browserlink-throws-an-exception-when-using-angularjs-and-binding-in-an-attribute-browserlink-does-not-like-in-a-html-attribute
The following link includes a similar description of the error you have and a few ways to disable the browser link feature:
http://www.telerik.com/forums/the-new-browser-link-feature-in-vs-2013-is-causing-an-error-when-detailtable-of-hierarchy-radgrid-is-expanded

Windows Phone - Cordova - Select crash

I've got a strange problem on my Windows Phone 10 App.
Setup:
Cordova 6.2
Windows Platform 4.4.2
Angular 1.5.5
Angular Material v1.1.0-rc.5
Angular-Translate v.2.7.2
Inside my app I got a select-control:
<select style="width:100%;height:40px;margin-top:10px;margin-bottom:10px;" ng-model="isoCodeList.region">
<option ng-repeat="entry in ::isoCodeList.list track by $index" value="{{::entry}}">
{{::"ISO_" + entry | translate}}
</option>
</select>
The isoCodeList looks like:
$scope.isoCodeList.list = ['AD', 'AE', 'AF', 'AG',...]
The translation labels looks like:
"ISO_AE": "United Arab. Emirates"
When I open the select-control 1 second later the app crashes.
The problem doesn't exists while I debug the app via Visual-Studio, it just occures when the App is deployed and downloaded from the Windows-Store.
Also this issues doesn't occure on a Windows-Phone 8.1 device, just on Windows-Phone 10, but both get the same .appx-file.
Anyone experienced the same problem?
PS: I can't use the standard angular-material md-select because it needs more then 20 to 30 seconds to open the whole control.
Thanks in advance
Graphefruit

AngularJS: Error while interpolating: {{ $index + 1 }}

I used $index inside simple ng-repeat to show items' number:
<li ng-repeat="item in dataList | limitTo:5">
<span>{{ $index + 1 }} </span>
</li>
And it worked OK for long time.
But sudden couple days ago I started getting:
Error: Error while interpolating: {{ $index + 1 }} illegal access
at Error (native)
at Object.k (/vendors/angular/angular.min.js:55:287)
at Object.e.$digest (/vendors/angular/angular.min.js:90:233)
at Object.e.$apply (/vendors/angular/angular.min.js:92:431)
at Object.<anonymous> (/js/controllers/HomePage.js:99:28)
at l (/vendors/jquery/jquery.min.js:4:24797)
at Object.c.fireWith [as resolveWith] (/vendors/jquery/jquery.min.js:4:25618)
at k (/vendors/jquery/jquery.min.js:6:5201)
at XMLHttpRequest.<anonymous> (/vendors/jquery/jquery.min.js:6:9005)
at both production and local environments.
Data in dataList is correct and the same as was all time previous.
It is reproducible only in latest Chrome (32.0.1700.14) in other browsers it still working correct.
Any ideas why this can happen and how it can be fixed?
Angular version: 1.1.5.
Debugging showed that exception is thrown from angular.js:6371 on native adding operation, and it is not about AngularJS itself.
For those who are getting same issue, looks like the only solution is to find any alternative way of implementing your task on which it is failing. At least till next Google Chrome update.
Thanks to #Heikki for pointing to chromium issues tracker.
Since the bug is related to String + Number concatenation I am using toString() on the numbers as a temp workaround.
{{($index + 1).toString()}}
worked in my case.

postLink generates invalid code at CakePHP 2.3

I am using CakePHP 2.3
I have two environments where I have my web application. At the testing environment with the exact same version of the application (all files are the same) I am having a problem with the Form->postLink method.
It shows this error on the Javascript console:
Uncaught TypeError: Object # has no method 'submit' users:119
onclick
Comparing the resulting HTML from both environments I can notice that the attributes name and id generated by this method are repeated more than once in the same page (which shouldn't be like that).
This is the code use to generate those post links:
foreach($users as $user){
$delete = $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['user_id']), __('Are you sure you want to delete %s?', $user['user_id']));
}
This is the problematic generated HTML with repeated values for id and name as you can see:
<!-- link 1 -->
<form action="delete/1/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST"/>
</form>
Delete
<!-- link 2 -->
<form action="delete/2/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST"/>
</form>
Delete
Why is this happening?
Could it be related with the configuration of the web server somehow? I don't see another explanation for it...
Thanks.
The problem was caused by a bug in IIS 7.0.6000.16386 and the PHP function uniqid as pointed out here.
I am using a slightly different version in both environments ( IIS 7.0.6000.16386 vs IIS 7.5.7600.16385) and that was the cause of the problem.
In order to solve it I modified the file lib/Cake/View/Helper/FormHelper.php chaning the line $formName = uniqid('post_'); inside the postLink function to:
$formName = uniqid('post_', true);
That adds more entropy and as the documentation says:
If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.
Update
Ended up having to add one more change due to problems with javascript in forms.
I added one more line after $formName = uniqid('post_', true); so it looks like:
$formName = uniqid('post_', true);
$formName = str_replace('.', '', $formName);

Resources