click event is not working in selenium - selenium-webdriver

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)

Related

Unable to click play button coming on mouseover of WebElement in a WebElement List- using serenity and webdriver

I got a list of webelement using xpath = ".//div[#id='list']/ul/li"
now li tag has child tags
<div class="abc-box " tabindex="-1">
<div class="abc-img b-loaded" tabindex="-1" style="background-image: url("/binaries/abc.jpg");">
<a class="game-img__link" data-gameid="1569" tabindex="-1" title="abc" href="/1816/launchSocialGame.do?launch=real" rel="nofollow">abc</a>
</div>
<div class="abc-overlay" tabindex="-1">
<a class="abc-overlay__link" data-gameid="1569" href="/1816/launch.do?launch=real" tabindex="-1" rel="nofollow">Play</a>
</div>
</div>
I am successfully getting <a> inside first <div>/<div> to verify the title="abc". Now if title=abc, I need to click second<a> as on mouseover/click on the webelement(image) of the list, play button get overlayed.
code i am using
public void click(String gameName) {
Webelement list=getDriver().findElement(xpath = ".//div[#id='list']/ul/li");
Iterator var2 = this.list.iterator();
while(var2.hasNext()) {
WebElement we = (WebElement)var2.next();
WebElement gameImage= we.findElement(By.tagName("a"));
if (gameImage.getAttribute("title").toLowerCase().contains(gameName.toLowerCase())) {
withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS);
(new WebElement playLink = we.findElement(By.className("abc-overlay__link")); withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS).waitFor(ExpectedConditions.visibilityOf(playLink));
playLink.sendKeys(Keys.RETURN);
clickedGame=true;
break;
}else{
clickedGame=false;
}
}
}
With above code, I am getting exception of timeout on
withTimeoutOf(SECONDS_TO_WAIT, TimeUnit.SECONDS).waitFor(ExpectedConditions.visibilityOf(playLink));
Tried many thing to get correct locator of play button but all attempts unsuccessful. I am not able to understand where am I doing wrong.
Please suggest how to click on play button.
Thanks

Query over selenium automation

I am doing automation but unable to click on a hyperlink by using findElement(). Sharing that part of the inspect elment of the code . Can anyone help ?
<div class="nametag" data-request-type="immigration">
</div>
<div class="name">
</div>
<div class="info">
Click <a href="" ng-click="openNewRequest(currentUserInfo.personId, 2)">
here</a> to submit new visa request.
Considering your element code, you can use linktext to click on hyperlink. Use the below generic function to click. Following code is in c#:
click(By.LinkText("here"));
public void click(By by) //method starts from here
{
try
{
WebDriverwait wait;
wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.elementToBeClickable(by)).click();
}
catch(WebDriverException er)
{
}
}
you can do this:
WebElement e = driver.findElement(By.cssSelector(".info a"));
String href = e.getAttribute("href");
driver.get(href); or driver.navigate().to(href);
Try Using css selector. Here's the full code.
By linkLocator = By.cssSelector("[data-request-type="immigration"] .info a");
driver.findElement(linkLocator).click();
Use explicit wait before click. you can use below xpath for click on hyperlink.
driver.findElement(By.xpath("//a[text() = 'here']"));
For how to use explicit wait please go to below link.
https://trickyautomationworld.blogspot.in/2018/02/implicit-wait-vs-explicit-wait-vs.html

Selenium Click when onclick="return false;"'

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

how to show a modal dialog box on a button click using mobile-angular-ui

Mobile Angular UI Is getting popular which is nothing but bootstrap 3 and angularjs combination
I would like to create a modal dialog box on button click and close the dialog on close icon, how to do it?
Based on the docs it says
<div ui-content-for="modals">
<div class="modal" ui-if="modal1" ui-state='modal1'>
.....
</div>
</div>
But how to call this dialog, I tried this
<button ui-turn-on="modal1" class="btn btn-primary">Show Model</button>
But it is not working as expected, I am getting Warning: Attempt to set uninitialized shared state: modal1error
I think you have placed ui-content-for inside the ui-yield-to
Put it outside that div tag as follows
<div ui-yield-to="modals"></div>
<div ui-content-for="modals">
<div class="modal" ui-if="modal1" ui-state="modal1">
....your model html code
</div>
</div>
So that modals will remain as a place holder

Error using AngulaJS and SimpleModal jQuery plugin together

I'm trying to open a modal using SimpleModal OSX, and the values for some of the attributes are assigned using AngularJS. However, when I click an item to open a new modal it doesn't work and the page reloads. Here's the code to make this clear
<li ng-repeat="news in newsItems" class="some class">
<a class="osx" href="#" data-page={{news.dataPageUrl}}>
<article>
<header>
<span class="itemtype">{{news.dateHeader}}</span>
<h1>{{news.header}}</h1>
</header>
<img height="145" src={{news.imageUrl}} alt={{news.imageHeader}} />
</article>
</a>
</li>
The dynamic items appear in my page, so the ng-repeat directive works. I added a static item and it opens a new modal without issues. The osx.js script is loaded at the end of the body tag. What am I doing wrong?

Resources