WebDriver: Locating elements with Dynamic Ids embedded in a string - selenium-webdriver

Could anyone suggest how I can locate the element "ToBeSelected" that has the below html code:
<div id="Locate-17-tab-info" class="tab active" data-tab-name="tobeselected"> ToBeSelected </div>
The XPath
driver.findElement(By.xpath("input[contains(#id, '-tab-info')]")).click();
I did not have success with finding by XPath - starts-with and ends-with.

You May try
driver.findElement(By.xpath(//input[contains(#id,'Locate') and text()='ToBeSelected'])).click();

Related

Cannot get a valid selector to implement I.click()

I am trying to click a button that has these details when I F12
<a data-codecept="searchGo" id="9" class="a-button a-button--white clearfix block showall" suggestrow"="" alt="/s/lundhags/?searchparam=lundhags" onmouseover="suggest.handleMouseOver(9);" onmouseout="suggest.handleMouseOut(9)" onclick="suggest.handleSubmit();" xpath="1">Show all results for 'lundhags'<span class="a-icon a-button__icon a-button__icon--double-arrow"></span></a>
I have copied xpath and I had a code like this=>
I.click('//*[#id="9"]');
and I got this error
Clickable //*[#id="9"] was not found by text|CSS|XPath
What am I doing wrong?
It works now! I used the specific Identifier
I.click('[data-codecept="searchGo"]');

Selenium Webdriver angular.js button

I have the code which I am trying to run in Selenium webdriver. It is a button but I can't select it with java code. Can you please help me which is true ?
<mat-list-item _ngcontent-c7="" class="menu-item mat-list-item ng-star-inserted" id="kisiler"><div class="mat-list-item-content"><div class="mat-list-item-ripple mat-ripple" mat-ripple=""></div><div class="mat-list-text"></div>
<!----><mat-icon _ngcontent-c7="" class="mat-icon material-icons ng-star-inserted" role="img" aria-hidden="true">group</mat-icon>
<!---->
<!----><mat-label _ngcontent-c7="" class="ng-star-inserted">Kişiler</mat-label>
</div></mat-list-item>
My code is:
driver.findElement(By.id("[#id='kisiler']")).click();
To click on the element with text as Kisiler you need to induce WebDriverWait for the element to be clickable and you can use the following solution:
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//mat-list-item[#class='menu-item mat-list-item ng-star-inserted' and #id='kisiler']//mat-label[#class='ng-star-inserted']"))).click();

angular dir-paginate paginate-id error

i have a list and within that list i have a new list that needs to be paginated. To make sure that each inner list know which list they belong to i use: pagination-id:
<div class="list-group bg-white m-none b-t">
<span dir-paginate="module in category.organization_has_modules | itemsPerPage:10 | filter:search"
pagination-id="category.id">
<a ui-sref="app.library_assign({module_id:module.module.id})"
class="list-group-item"
ng-if="module.is_active != 0">
<i class="fa fa-fw {{module.module.module_type.icon}}"></i>
{{module.module.name}}
<span class="pull-right">
<i class="fa fa-sign-in"></i>
</span>
<div class="clear"></div>
</a>
</span>
<dir-pagination-controls class="pull-right" pagination-id="category.id"></dir-pagination-controls>
When i run this i sadly get the following error message:
error: [$parse:syntax] Syntax Error: Token '__currentPage' is an unexpected token at column 4 of the expression [103__currentPage] starting at [__currentPage].
if i run it without the pagination-id it runs fine however it is unable to differ the different lists which means all the pages change when i change it in one of the lists.
Does anyone have any idea of what im doing wrong?
The problem was apprently a bug with the id being a number. The parser in dirPagination.js line 206 does not accept numbers and the regex created to replace any numbers is apprently not working. So instead of using a number i used a string.

Unable to get value from paper-input

<question-chrome question="{{question}}">
<paper-input label="{{question.Description}}" id="answer" name="answer" type="number">
{{question.Description}}
</paper-input>
</question-chrome>
Where question-chrome.html has the followign code:
<template>
<div class="questioncontainer {{question.Type }}" style="padding-top:10px;">
<div class="questiontext">
<span class="questiontitle">{{question.Title}}</span>
</div>
<div class="questionanswers">
<content select=".questionanswers"></content>
</div>
</div>
</template>
I am using the above paper input, when I am trying to get the values from this, I cannot find the value anywhere. the question element/object, I can get and see every other item's value of the question object. How would I get the value of what is put into the input field? in this case, the value was 3323.
this:
The code to retrieve it I have tried all of these:
this.$.answer.value;
And the results through developer tools in chrome result in:
Object
AdditionalProperties:null
Answers:Array[0]
Code:720061
Description:"Monetary marks ...."
ExtensionData:null
HasAnswers:false
HasChildren:false
Id:"9999dcc3-d3eb-40cf-8414-05ae385e11cf"
IsDefault:true
IsDeleted:false
.....so on and so forth
I went through all of these and did not find it. It is a numeric type of field, so not sure if that has anything to do with it.

angularjs + yeoman + ng-switch + build:minify -> assertion

I am using an ng-switch in angularjs to have dynamic content in my page, dependent on the url. And I am managing my project with yeoman. Here is the code of the dynamic content generation:
html:
<div class="div-content bgcontent" id="content">
<span ng-switch on="renderPath[0]">
<div ng-switch-when="home" ng-include="'partials/home.html'"></div>
<div ng-switch-when="gallery" ng-include="'partials/gallery.html'"></div>
</span>
</div>
controller:
$scope.renderPath = $location.path().split('/');
// remove first entry because it's empty string
$scope.renderPath.shift();
This works perfectly well when running the stuff with 'yeoman server'. But if I build with 'yeoman build:minify', it doesn't work anymore afterwards. It hits an assertion:
at assertArg (http://host:8888/scripts/vendor/d10639ae.angular.js:973:11)
at Object.ngDirective.compile (http://host:8888/scripts/vendor/d10639ae.angular.js:13474:5)
at applyDirectivesToNode (http://host:8888/scripts/vendor/d10639ae.angular.js:4047:32)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3794:14)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3799:14)
at compile (http://host:8888/scripts/vendor/d10639ae.angular.js:3739:29)
at update (http://host:8888/scripts/vendor/d10639ae.angular.js:13685:22)
at $get.Scope.$broadcast.next (http://host:8888/scripts/vendor/d10639ae.angular.js:8002:24)
at Array.forEach (native)
at forEach (http://host:8888/scripts/vendor/d10639ae.angular.js:110:11) <!-- ngSwitchWhen: home -->
Does someone know how to fix this? Or where I need to look to debug it?
If you are using dependency-injection within your scripts, make sure to use the minify-proof syntax as described here: http://docs.angularjs.org/guide/di

Resources