Selenium Click when onclick="return false;"' - selenium-webdriver

In web page,there are few tabs like CustomerAccountContact.
These tabs are inside SPAN html tag.
PFB, the html source code for accounts tab:
<a class="x-tab-right" onclick="return false;" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">
Account
</span>
</span>
</em>
</a>
I have tried the below click methods apart from the normal click,but none worked:
1.JavascriptExecutor executor = (JavascriptExecutor) browser;
executor.executeScript("arguments[0].click();", we);
2.
Actions builder = new Actions(browser);
builder.moveToElement(we).click().perform();
In QTP, using device reply I was able to click on the tab as that it stimulated the mouse click method
Please suggest on how to stimulate the mouse click and click the 'Accounts' tab

Related

angular-xeditable onsave event

I am using angular package angular-xeditable the problem is I want to call its event onaftersave after i edit the label here is my html:
<h4 >{{ title.key || 'empty' }}
<span onaftersave="save()" editable-text="title.key ">
<i class="fa fa-pencil-square-o" "></i></span>
</h4>
the event onaftersave is called even if i click on the edit button and also while typing in the field
what I want is to call the event only when I click the button
Try to use this code this will helps to prevent function call.
<span>
<a onaftersave="save();" data-ng-model="title.key" e-placeholder="Your text" editable-text="title.key">
<span>{{title.key || 'empty'}}</span>
</a>
</span>

click event is not working in selenium

My scenario is - after login, dashboard page is displaying ,there I want to click on a link. which will give a javascript popup. Though my xpath is correct it is not clicking on it. And the test is also showing pass.
I have attached both html and selenium code -
Html :
<!-- create connection section -->
<section class="wrangler-create-project left-align">
<div class="container">
<a class="btn z-depth-0" data-target="create-project-modal"><i class="fa fa-plus-circle left" aria-hidden="true"></i>New project</a>
</div>
</section>
Selenium Code :
#Test
public void clickNewProject() throws TimeoutException
{
UtilsMethods.login();
WebDriverWait wait = new WebDriverWait(UtilsMethods.driver, 40);
System.out.println(UtilsMethods.driver.getPageSource());
wait.until(ExpectedConditions.presenceOfElementLocated (By.xpath("//a[#data-target='create-project-modal']")));
UtilsMethods.driver.findElement(By.xpath("//a[#data-target='create-project-modal']")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[#id='project_name']")));
}
we can keyboard action events,
UtilsMethods.driver.findElement(By.xpath("//a[#data-target='create-project-modal']")).sendKeys(Keys.Enter)

AngularJS unable to update ng-repeat items failure in table "edit mode"

I am trying to implement a "edit mode" feature.
When edit button is clicked, function backup will back up the item.
When save button is clicked, function save will save it.
But it does not work for Recover
<a><i class="fa fa-lg" ng-click="item.editable? item.enable = !item.enable:''" ng-class="item.enable? 'fa-toggle-on text-success': 'fa-toggle-off text-danger'"></i></a>
<a ng-if="!item.editable"><i class="fa fa-lg fa-pencil-square text-primary" ng-click="backup(item)"></i></a>
<a ng-if="item.editable"><i class="fa fa-lg fa-check-square text-primary" ng-click="save(item)"></i></a>
<a ng-if="item.editable"><i class="fa fa-lg fa-reply text-danger" ng-click="recover(item)"></i></a>
Plunker
Please look at my Edited plunker .. I've added an angular.extend(item, backup_item) to properly update the item object with it's backup.
Hope this helps

how to click on an element which is hidden/not displayed in selenium webdriver?

Need to click on New button. How do I proceed with it, as it's not displayed/visible? This is the concerned code-
<li tabindex="-1" class="ms-crm-CommandBarItem ms-crm-CommandBar-Menu ms-crm-CommandBar-Button" title="NewCreate a new Account record." id="account|NoRelationship|HomePageGrid|Mscrm.HomepageGrid.account.NewRecord" command="account|NoRelationship|HomePageGrid|Mscrm.NewRecordFromGrid" style="white-space: pre-line; display: inline-block;"><span tabindex="-1" class="ms-crm-Menu-Label ms-crm-CommandBar-Button" style="max-width:200px"><a tabindex="0" class="ms-crm-Menu-Label" onclick="return false"><img tabindex="-1" class="ms-crm-ImageStrip-New_16 ms-crm-commandbar-image16by16" src="/_imgs/imagestrips/transparent_spacer.gif" style="vertical-align:top" alt="New"> <span tabindex="-1" class="ms-crm-CommandBar-Menu" style="max-width:150px" command="account|NoRelationship|HomePageGrid|Mscrm.NewRecordFromGrid"> New </span> </a> </span> </li>
Since, it is hidden the only way to click the element is to execute the javascript and perform click with javascript executor.
I assumed you are using Selenium java binding since you have not mentioned that.
//Find the element to click on.
//Selenium will find the element without any issue
//since it is present in the DOM
//I assumed you want to click on the <code>span</code> with text New
//since there is no actual button
WebElement element = driver.findElement(By.cssSelector("[title='NewCreate a new Account record.']>span>a>span"));
JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
jsExecutor.executeScript("arguments[0].click();", element);

Protractor: how to click menu element from dropdown list menu

I have dropdown menu like this:
PROJECTS v
View Projects
Add Project
I want protractor to click "Add Project" element. To do this user has to click down arrow (v character) first to show 2 sub elemnts (View Projects, Add Project).
The is the code:
<div class="dropdown btn-group open" ng-show="canAccessProjects">
<button class="dropdown-toggle btn navbar-btn btn-success" ng-class="{'btn navbar-btn btn-success': isActive('/project'), 'btn navbar-btn btn-info': !isActive('/project')}" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><div class="dropdown-option ng-binding" role="menuitem" tabindex="-1" ng-click="menuButtonClicked('/project')">View Projects</div></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><div class="dropdown-option ng-binding" role="menuitem" tabindex="-1" ng-click="menuButtonClicked('/project/add/step0')">**Add Project**</div></li>
</ul>
</div>
Can protractor click on the "Add Project" link before clicking white arrow? (user can't)
How to click this element (Add Project) - div nas no ID, only differs by CSS - should I do that by
element(by.css('.menuButtonClicked('/project/add/step0')'))
protractor cannot click an invisible element - as a real user cannot. "Add Project" can be found either by text, or by index, or relying on the ng-click.
Let's, for the sake of an example, use by.xpath. Here I'm finding the arrow button, clicking it and getting the following ul sibling, then using last() to get the last li in the list:
var button = element(by.id('dropdownMenu1'));
button.click();
button.element(by.xpath('following-sibling::ul/li[last()]/div')).click();
This is how I do it in the e2e test for the protractor website:
// Page object
$('.dropdown.open')
.element(by.linkText(itemName))
.click();
// And this is how it looks like in the test:
var menu = require('./menu-partial');
menu.dropdown('Protractor Setup').item('Setting Up the Browser')
https://github.com/angular/protractor/blob/master/website/test/e2e/menu-partial.js#L43

Resources