Not possible to locate an element using selenium webdriver with java - java

I am automating an application using selenium webdriver with java. I'm facing the issue that cannot locate an element in a page.
HTML Code:
<main id="main-section">
<div class="main-content">
<div class="ng-scope" ng-controller="EventsController as eventcntrlr">
<div class="full-banner">
<section class="dashboard-tournaments">
<div class="" ng-show="eventcntrlr.noTournamentsFound==2" style="">
<div class="dt-title" ng-show="eventcntrlr.upcomingTournamentsCount !=0" style="">
<div class="dtslider" ng-show="eventcntrlr.upcomingTournamentsCount !=0" style="">
<div class="bx-wrapper" style="max-width: 810px; margin: 0px auto;">
<div class="bx-viewport" style="width: 100%; overflow: hidden; position: relative; height: 0px;">
<ul class="bxslider upcomingSliderClass no-slide" ng-class="{'no-slide':eventcntrlr.upcomingTournamentsCount<eventcntrlr.SlideCount}" style="display: block; width: 415%; position: relative; transition-duration: 0s; transform: translate3d(0px, 0px, 0px);">
<!-- ngRepeat: allupcoming in eventcntrlr.upcomingTournaments -->
<li class="upcomingSpanHeight ng-scope" ng-repeat="allupcoming in eventcntrlr.upcomingTournaments" style="float: left; list-style: outside none none; position: relative; width: 400px; margin-right: 10px;">
<span class="ratio-width upcoming-spanWidth" style="height: 205px;"/>
<div class="dtslider-block">
<div class`enter code here`="dtslider-content">
<img ng-src="../../category/music.jpg" alt="slienter code hereder" src="../../category/music.jpg"/>
<div class="hover-contents">
Code:
public void playTournament() throws InterruptedException, BiffException,IOException {
int successRowNumber = 7;
WebElement login = driver.findElement(By.xpath("//*[#id='main-section']/div/div/section[2]/div[1]/ul/li[1]"));
login.click();
Thread.sleep(1000);
WebElement username = driver.findElement(By.xpath("//*[#id='emailtxt']"));
username.clear();
username.sendKeys(getCellContent(0, successRowNumber));
Thread.sleep(1000);
WebElement password =driver.findElement(By.xpath("//*[#id='passwordtxt']");
password.clear();
password.sendKeys(getCellContent(1, successRowNumber));
Thread.sleep(1000);
WebElement continueButton = driver.findElement(By.xpath("//*[#id='main-section']/div/div/section[2]/div[3]/a/span ");
continueButton.click();
Thread.sleep(4000);
WebElement events = driver.findElement(By.xpath("//*[#id='events_li']/a");
events.click();
Thread.sleep(2000);
input(properties.getProperty("VAR_GROUPPINDETAILS"));
int successfulTournamentCreationRowNumber = 12;
WebElement tournamentSearch = driver.findElement(By.xpath("//*[#id='ContentPlaceHolder1_searchname']");
tournamentSearch.sendKeys(getCellContent(1, successfulTournamentCreationRowNumber));
Thread.sleep(2000);
WebElement findEvent = driver.findElement(By.xpath("//*[#id='main-section']/div/div/div/section[2]/div/div/div[5]/a");
findEvent.click();
Thread.sleep(2000);
WebElement Tournaments = driver.findElement(By.xpath("//*[#id='main-section']/div/div/section/div[1]/div[2]/div[1]/div[1]/ul/li[1]/div/div[1]/div");
Tournaments.click();
Got the error msg: org.openqa.selenium.ElementNotVisibleException: element not visible.
Issue is for the element "Tournaments "

Related

How to get value from a list which is not a drop down in selenium

<div class="Select form-control undefined Select--single is-searchable has-value"><input name="deal.listdealasset[0].acacode" type="hidden" value="NEWCAR"><div class="Select-control"><span class="Select-multi-value-wrapper" id="react-select-3--value"><div class="Select-value"><span class="Select-value-label" id="react-select-3--value-item" role="option" aria-selected="true">New</span></div><div class="Select-input" style="display: inline-block;"><style>input#undefined::-ms-clear {display: none;}</style><input role="combobox" aria-expanded="false" aria-haspopup="false" aria-activedescendant="react-select-3--value" aria-owns="" style="width: 19px; box-sizing: content-box;" value="" data-rxName="deal.listdealasset[0].acacode"><div style="left: 0px; top: 0px; height: 0px; text-transform: none; letter-spacing: normal; overflow: scroll; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-weight: 400; white-space: pre; visibility: hidden; position: absolute;"></div></div></span><span class="Select-arrow-zone"><span class="Select-arrow"></span></span></div></div>
I'm trying to select a value from a drop-down but its html tag is not select.
I have tried various options but none work.
WebElement optionsList = driver.findElement(By.xpath("//span[contains(#class, 'Select-multi-value-wrapper')]"));
List<WebElement> options = optionsList.findElements(By.xpath("//span[contains(#class, 'Select-value-label')]"));
options.get(0).click();
I want to select the value new from drop down.[]
I'm getting below error on execution -
Element could not be scrolled into view
Below is the HTML code for the page-
<div class="Select form-control undefined Select--single is-searchable has-value">
<input name="deal.listdealasset[0].acacode" type="hidden" value="NEWCAR">
<div class="Select-control">
<span class="Select-multi-value-wrapper" id="react-select-3--value">
<div class="Select-value"><span class="Select-value-label" id="react-select-3--value-item" role="option" aria-selected="true">New</span></div>
<div class="Select-input" style="display: inline-block;">
<style>input#undefined::-ms-clear {display: none;}</style>
<input role="combobox" aria-expanded="false" aria-haspopup="false" aria-activedescendant="react-select-3--value" aria-owns="" style="width: 19px; box-sizing: content-box;" value="" data-rxName="deal.listdealasset[0].acacode">
<div style="left: 0px; top: 0px; height: 0px; text-transform: none; letter-spacing: normal; overflow: scroll; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-weight: 400; white-space: pre; visibility: hidden; position: absolute;"></div>
</div>
</span>
<span class="Select-arrow-zone"><span class="Select-arrow"></span></span>
</div>
</div>
Since your drop down is made of Div and span tags, Select class will not work from selenium.
Code you can try :
List<WebElement> options = driver.findElements(by.xpath(" your locator"));
for(WebElement element : options){
if(element.getText().equals(" your value from drop down")){
element.click();
}
}
Let me know, if you have any more concerns.
Since You are getting error of element can not be scrolled into view.
You should try JavascriptExecutor for scrolling.
This way will allow you to scroll horizontally/vertically page
((JavaScriptExecutor)driver).executeScript("scroll(0,200)") - only scroll vertically by 200 pixels
2 . For bringing element into Focus
((JavaScriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
Since option 'new' had id attribute defined, clicking object is straight forward by using id.
Below code should work, provided that dropdown button is already clicked.
driver.findElement(By.id("react-select-3--value")).click();
driver.findElement(By.id("react-select-3--value-item")).click();
Thanks for the response .
It worked with below query i.e by merging send keys and keys.enter-
driver.findElement(By.id("react-select-3--value")).click();
driver.findElement(By.xpath("/html/body/section/div/div[2]/section/div/from/div/div[3]/div[1]/div/div/div[2]/div/div/div/div/div/span[1]/div[2]/input")).sendKeys("New",Keys.ENTER);

Scrolling PDFs in iOS with iFrame

I'm trying to scroll this pdf: ifcharts.ml/KSAN.html
I've got this so far:
<section class="features section-padding" id="features">
<div class="container">
<div class="row">
<div class="feature-list">
<h3>San Diego</h3>
<p>Departure</p>
<div>
<iframe class="js/scroll-wrapper.js" src="http://flightaware.com/resources/airport/SAN/APD/AIRPORT+DIAGRAM/pdf" width="600" height="700"></iframe>
<iframe class="js/scroll-wrapper.js" src="https://flightaware.com/resources/airport/KSAN/DP/all/pdf" width="600" height="700"></iframe>
</div>
<p>Approach</p>
<div>
<iframe class="js/scroll-wrapper.js" src="https://flightaware.com/resources/airport/KSAN/STAR/all/pdf" width="600" height="700"></iframe>
<iframe class="js/scroll-wrapper.js" src="https://flightaware.com/resources/airport/KSAN/IAP/all/pdf" width="600" height="700"></iframe>
</div>
</div>
</div>
</div>
</section>
The class="js/scroll-wrapper.js" leads to this:
.scroll-wrapper {
position: fixed;
right: 0;
bottom: 0;
left: 0;
top: 0;
-webkit-overflow-scrolling: touch;
overflow-y: scroll;
}
.scroll-wrapper iframe {
height: 100%;
width: 100%;
}
That is what the the script is meant to run, however it still is not scrolling on iOS.
I also have a problem where it is downloading the code on Android. How can I set it now to download?
Thanks

Open a Record from MSCRM Dashboard by Selenium Webdriver

I am writing Script to open a Record from Dash Board of MSCRM 2011. Those Records are arranged in table as Checkbox inside a Frame. So on double click of Checkbox Record Page will open
Below is Exception which i am getting
java.util.NoSuchElementException
at java.util.LinkedHashMap$LinkedHashIterator.nextEntry(Unknown Source)
at java.util.LinkedHashMap$KeyIterator.next(Unknown Source)
at Ford_Account.main(Ford_Account.java:112)
Below is Webdriver Code
WebElement link = w1.findElement(By.xpath("html/body/div[5]/div[1]/div[2]/span/ul/li[2]/ul/li[1]/a[1]")); //COntact click
link.click();
w1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
try {
windows= w1.getWindowHandles();
iterator=windows.iterator();
while((iterator.hasNext())){
parent=iterator.next();
child=iterator.next();
w1.switchTo().window(child);
System.out.println("Swicthed to child");
Thread.sleep(1000);
}
w1.switchTo().frame("contentIFrame");
Actions ac = new Actions(w1);
WebElement element = (WebElement) ac.moveToElement(w1.findElement(By.id("checkBox_{EE9744AC-6737-E511-8459-E4115BDF9DFD}")));
ac.doubleClick(element).perform();
I am Getting Exception on
child=iterator.next();
Below is HTML Structure
<iframe id="contentIFrame" frameborder="0" name="contentIFrame" style="border: 0px none; overflow: hidden; position: absolute; left: 0px; right: 0px; height: 100%; width: 100%; opacity: 1; display: inline;" title="Content Area" src="/_root/homepage.aspx?etc=1&pagemode=iframe&sitemappath=CS%7cCS%7cnav_accts&whr=https%3a%2f%2fmscrm00b.hpuscrmpoc.com%2fadfs%2fservices%2ftrust">
<!DOCTYPE html>
<html webdriver="true">
<head>
<body class="stage">
<div class="stdTable">
<span id="__Page_crmEventManager" style="display:block;height:0px;"></span>
<div></div>
<div>
<div style="height:0px;">
<div id="homepageTableCell" class="ms-crm-absolutePosition" style="top:27px;">
<div class="ms-crm-IE7-Height-Fix-Dummy-Container">
<div id="crmGrid_visualizationCompositeControl" style="height:100%;">
<div id="crmGrid_compositeControl" style="height:100%;width:100%;position:relative;">
<div id="crmGrid_crmGridStrip" class="ms-crm-CC-GridSS-All-0-LR">
<div id="crmGrid_crmGridTD" class="ms-crm-CC-grid-All-0-LR">
<div class="ms-crm-IE7-Height-Fix-Dummy-Container">
<div id="crmGrid_filterSet" gridid="crmGrid"></div>
<div class="ms-crm-grid-BodyContainer" style="width:100%;height:100%;position:relative;overflow:hidden;">
<div id="crmGrid" class="ms-crm-ListControl" type="crmGrid">
<div class="ms-crm-grid-body" style="bottom:25px;">
<div class="ms-crm-IE7-Height-Fix-Dummy-Container">
<div id="crmGrid_gridBodyContainer" class="ms-crm-grid-BodyContainer" style="height:100%;position:relative">
<div id="refreshButton" class="ms-crm-List-RefreshButton" style="left: auto; right: 0px; display: inline;">
<div class="ms-crm-ListArea" style="position:relative">
<div class="ms-crm-grid-BodyContainer" style="height:22px;OVERFLOW-X:hidden;">
<div class="ms-crm-grid-databodycontainer" style="top:22px;bottom:22px;vertical-align:top">
<div class="ms-crm-IE7-Height-Fix-Dummy-Container">
<div id="crmGrid_divDataBody" class="ms-crm-List-DataBody">
<div id="crmGrid_divDataArea" class="ms-crm-List-DataArea" expandable="0">
<div>
<table id="gridBodyTable" class="ms-crm-List-Data" cellspacing="0" cellpadding="1" border="1" style="border-style:None;border-collapse:collapse;" summary="This list contains 7 Account records." primaryfieldname="name" tabindex="0" numrecords="7" oname="1" allrecordscounted="1" totalrecordcount="7" morerecords="0" rules="rows">
<colgroup>
<thead>
<tbody>
<tr class="ms-crm-List-Row" otypename="account" otype="1" oid="{21C2F87E-9E36-E511-8459-E4115BDF9DFD}">
<td class="ms-crm-List-NonDataCell" align="center">
<input id="checkBox_{21C2F87E-9E36-E511-8459-E4115BDF9DFD}" class="ms-crm-RowCheckBox" type="checkbox" style=" " title="ford Account123" tabindex="0">
</td>
Can anyone Suggest me how to open a record from dashboard of MSCRM 2011

Confusion with Remember username codes(javascript)?

I started learning javascript and i have a question with a webpage that i created. The webpage is a login page that shows some tableau reports when logged in. I need to create a remember me checkbox just like any other website like gmail or salesforce. I have copy pasted the codes below.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%
ServletContext context = getServletContext();
String app = context.getInitParameter("appName");
String errorMessage = "";
if ( session.getAttribute("error-message")!=null){
errorMessage = (String) session.getAttribute("error-message");
}
%>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><%=app%> - Please login</title>
<link href="styles/bootstrap-theme.min.css" rel="stylesheet">
<link href="styles/bootstrap.min.css" rel="stylesheet">
<link href="styles/sidebars.css" rel="stylesheet">
<link rel="shortcut icon" href="img/favicon.ico">
<style type='text/css' media='screen'>
body {
font-family: Tahoma;
font-size: 12px !important;
padding-top: 40px;
padding-bottom: 40px;
background-color: #fff;
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.navbar{
border-color: #ccc;
}
.alert-warning{
margin-top: 15px;
}
.validation-summary-errors{
font-family: Tahoma !important;
font-size: 12px !important;
color: #b94a48;
margin-top: 35px;
margin-bottom: -15px;
}
.col-md-8{
padding-left: 5px;
}
/* .navbar-inverse{
border-color: #ccc;
background: #ddf0f8; Old browsers
background: -moz-linear-gradient(top, #ddf0f8 0%, #ffffff 63%); FF3.6+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#ddf0f8), color-stop(63%,#ffffff)); Chrome,Safari4+
background: -webkit-linear-gradient(top, #ddf0f8 0%,#ffffff 63%); Chrome10+,Safari5.1+
background: -o-linear-gradient(top, #ddf0f8 0%,#ffffff 63%); Opera 11.10+
background: -ms-linear-gradient(top, #ddf0f8 0%,#ffffff 63%); IE10+
background: linear-gradient(to bottom, #ddf0f8 0%,#ffffff 63%); W3C
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ddf0f8', endColorstr='#ffffff',GradientType=0 ); IE6-9
}*/
</style>
</head>
<body>
<div class="navbar navbar-fixed-top" role="navigation">
<div class="navbar-header">
<img class="logo" src="img/Nexius_logo.png"/>
</div>
</div>
<div class='inner col-md-8'>
<%=errorMessage%>
<form action='LoginServlet' method='POST' id='loginForm' class='form-horizontal' role='form' autocomplete='off'>
<h4 class="form-signin-heading"> </h4>
<div class="form-group">
<label for='username' class='col-md-2 control-label'>User name</label>
<div class="col-md-4">
<input type='text' class="form-control" name='user' id='username' />
</div>
</div>
<div class="form-group">
<label for='password' class='col-md-2 control-label'>Password</label>
<div class="col-md-4">
<input type='password' class="form-control" name='pwd' id='password' />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button class="btn btn-default" type="submit">Login</button>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10"><div style="position: absolute; top: -45px; left: 100px; width: 240px;">
<input onClick="checkCookie()" type="checkbox" value="Remember me">Remember username<br>
</div>
</div>
</form>
</div>
<script type='text/javascript'>
function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname+"="+cvalue+"; "+expires;
}
function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name)===0) return c.substring(name.length,c.length);
}
return "";
}
function checkCookie()
{
var user=getCookie("user");
if (user!=="")
{
document.getElementById("username").value = user;
}
else
{
if (user!=="" && user!=null)
{
setCookie("user",user,30);
}
}
}
</script>
</body>
</html>
Mostly the upper part is just CSS. In the below part i have writtten the codes to get the username on the text box and pass it to the setcookie function below. So i need it like an usual page like when remember username check box was checked, the username should show up when the page is opened, but for me what it does is, when i open the webpage only when i click on the "remember username" checkbox the username pops up in the username textbox. Now sure what to do about this? Can someone please help me?
You're checking for cookies only when user clicks on the remember me button. You need to check for cookie on document load, for instance.
Add onload handler on body tag this way: <body onload=checkCookie()>. You need to also remove onClick="checkCookie()" from your remember me button.

How to select a <a href> javascript button using selenium java

I'm trying to click the "Add to Shopping Bag" button by utilising selenium (Java) interface on my AUT, but I'm unable to do so.
My script as follows:
public void addToBag()
{
WebElement AddToBag = null;
List<WebElement> SizeList = driver.findElement(By.className("selection-wrapper")).findElements(By.className("step-wrapper"));
for(WebElement e : SizeList)
{
if (e.getText() == " ")
{
if(e.findElement(By.tagName("span")).findElement(By.tagName("a")).getAttribute("href").contains("javascript:AddToCart()"))
{
AddToBag = e.findElement(By.tagName("span")).findElement(By.tagName("a"));
AddToBag.click();
break;
}
}
}
Thread.sleep(2000);
}
Source code:
<div class="subitem-steps span-12 last" style="z-index: 890;">`
<div class="item-styles span-12 last" style="z-index: 885;">`
<div class="selection-wrapper" style="z-index: 870;">`
<div class="step-wrapper" style="z-index: 869;">
<div class="step-wrapper" style="z-index: 863;">
<div class="step-wrapper" style="z-index: 857;">
<div class="step-wrapper" style="z-index: 851;">
<div class="step step4" style="z-index: 850;"/>
<span class="ui-btn-grey btn-add-to-cart btn-add-to-cart-sel">
<a href="javascript:AddToCart()" onclick="s_objectID="javascript:AddToCart()_1";return this.s_oc?this.s_oc(e):true"/>
</span>
<div class="external-links" style="z-index: 849;">
</div>
</div>
</div>`

Categories