Unable to locate element exception - c#-4.0

The exception
"{"Unable to locate element: {\"method\":\"xpath\",\"selector\":\"// > div[#class='item-content'][3]\"}"}"
The code
public static void Main ()
{
Login_FAM lgn = new Login_FAM();
Demat_Acount prg = new Demat_Acount();
lgn.Login();
prg.DematAdd();
}
// login.cs file //
public FirefoxDriver driver ;
public Login_FAM()
{
driver = new FirefoxDriver();
}
public void Login()
{
driver.Url = "http://180.211.114.147:97//Account/Login";
var usernameF = driver.FindElementById("UserName");
var passwdF = driver.FindElementById("Password");
var loginB = driver.FindElementById("btnLogin");
usernameF.SendKeys("harsh");
passwdF.SendKeys("harsh123");
loginB.Submit();
// Thread.Sleep(3000);
}
//demat_acount.cs file //
public FirefoxDriver driver;
public Demat_Acount()
{
driver = new FirefoxDriver();
}
public void DematAdd()
{
IWebElement pro = driver.FindElement(By.XPath("// div[#class='item-content'][3]"));
pro.Click();
if(pro != null)
{
pro.Click();
}
}
below is my HTML Code
<ul class="main-navigation-menu ng-scope" ng-controller="menuctrl">
<li ui-sref-active="active" class="active">
<a ui-sref="app.dashboard" href="#/app/dashboard">
<div class="item-content" style="padding-right:10px;padding-top:5px">
<div class="item-media">
<i style="font-size:20px" class="icon-Dashboard"></i>
</div>
<div class="item-inner">
<span class="title ng-scope">Dashboard</span>
</div>
</div>
</a>
</li>
<li ui-sref-active="active">
<a ui-sref="app.familydashboard" href="#/app/FamilyDashboard">
<div class="item-content" style="padding-right:10px;padding-top:5px">
<div class="item-media">
<i style="font-size:20px" class="icon-FamilyDashboard"></i>
</div>
<div class="item-inner">
<span class="title ng-scope">Family Dashboard</span>
</div>
</div>
</a>
</li>
<li ui-sref-active="active" class="open">
<a href="javascript:void(0)">`enter code here`
<div class="item-content" style="padding-right: 10px; padding-top: 5px">
<div class="item-media">
<i style="font-size:20px" class="icon-Profile2"></i>
</div>
<div class="item-inner">
<span class="title"> Profile </span>
<i class="icon-arrow" style="margin-top: 3px"></i>
</div>
</div>
</a>
<ul class="sub-menu" style="display: block;">
<li>
<li>
<a ui-sref="app.demataccount" href="#/app/DematAccount">Demat Account</a>
</li>
<li>
<a ui-sref="app.familyassociation"href="#/app/FamilyMemberAssociation">Family Association</a>
</li>
</ul>
</li>
</ul>
And FYI i have executed same code without creating methods and objects and that is working but crating method and objects it doesn't working

WebDriver could not find the element as your element is embedded in another div tag. Make sure your XPath is correct. Validate it using firepath. I'm new to automation, if I get this error, I'll verify my XPath.
Try changing XPath to
// div[#class='item-content'][3]/div/i
I'm not sure whether this might solve your problem or not, but trying to help. Make sure the element exists or put a wait until the element is visible.

Related

Apply style to all nested li div's excluding the first li div

No matter what I've tried to either target or exclude the first li div, nothing works. I tried :not(and different variations of the selectors here) but that didn't work. On one occasion, the result rendered as though looking into a mirror that's facing a mirror. No bueno. No classes or ids can be added--representative example below.
ul {
list-style-type: none;
}
.message-content-wrap {
background-color: red;
}
<ul id="thread-list" class="group-message-thread">
<li>
<div class="message-wrap group-messages-highlight">
<div class="avatar-wrap"></div>
<div class="message-content">
<div class="message-content-wrap">
<p>This is content in the first message</p>
</div>
</div>
</div>
</li>
<li>
<div class="message-wrap">
<div class="avatar-wrap"></div>
<div class="message-content">
<div class="message-content-wrap">
<p>This is content in the second message</p>
</div>
</div>
</div>
</li>
<li>
<div class="message-wrap">
<div class="avatar-wrap"></div>
<div class="message-content">
<div class="message-content-wrap">
<p>This is content in the third message</p>
<p>some text</p>
</div>
</div>
</div>
</li>
<li>
<div class="message-wrap">
<div class="avatar-wrap"></div>
<div class="message-content">
<div class="message-content-wrap">
<p>This is content in the fourth message</p>
<p>some more text</p>
</div>
</div>
</div>
</li>
</ul>
Any ideas would be most welcome. My attempt in jsfiddle
a few ways to style child elements
ul > li:not(first-of-type) {
// styles go here
}
ul > li {
// styles go here
}
ul:first-child {
}
li + li {
}

Need help removing active status on navigation menu

I just need the focus to stay once the element is clicked. I can't get it to work. This code below is from my masterpage. The hover works ok, but after clicking one of the menu options, it does not stay focused and goes right back to the home button. Can someone possibly shed some light on why this isn't working?
<body>
<script type="text/javascript" src="wz_tooltip.js"></script>
<form id="form1" runat="server">
<br />
<br />
<center>
<!-- start header -->
<header>
<div class="container">
<div class="navbar navbar-static-top">
<div class="navigation">
<nav>
<ul class="nav topnav bold" >
<li class="dropdown active">
<a id="nav1" href="../default.aspx" runat="server">HOME </a>
</li>
<li class="dropdown">
<a id="nav2" href="../reverse_mortgages.aspx" runat="server" onclick="setNavagation();">REVERSE MORTGAGE FAQ</a>
</li>
<li class="dropdown">
<a id="nav3" href="../loan_process.aspx" runat="server">OUR PROCESS</a>
</li>
<li id="nav4" class="dropdown">
GET QUOTE
</li>
<li id="nav5" class="dropdown">
ABOUT
</li>
<li id="nav6" class="dropdown">
CONTACT
</li>
</ul>
</nav>
</div>
<!-- end navigation -->
</div>
</div>
</header>
</center>
<script type="text/javascript">
function setNavigation() {
var path = window.location.pathname;
path = path.replace(/\/$/, "");
path = decodeURIComponent(path);
if (path.substring(1, path.length) === "") { // this was the home page loading already active
return;
}
$("li.active").removeClass("active"); // remove class 'active' all list items
$(".navigation a").each(function () {
var href = $(this).attr('href');
if (path.substring(1, path.length) === href) {
$(this).parent('li').addClass('active');
return;
}
});
}
</script>
<!-- end header -->

FlexSlider not working with MVC5 Framework

I am creating a website using MVC5 (we do for all our websites here) and I am trying to integrate the FlexSlider (found here: https://woocommerce.com/flexslider/) into one of my pages.
I can't seem to get it working, the page just displays nothing, yet it appears in the 'Inspect Element' with each image as being 0x0 px.
HTML:
<div class="flexslider" data-controlnav="thumbnails">
<ul class="slides">
#if (Model.CDSContent != null)
{
foreach (var item in Model.CDSContent)
{
<li>
<a href="#">
<img src="#Html.Raw(item["newsimage"])" alt="Slide 2">
<div class="flex-caption">newstitle</div>
</a>
</li>
}
}
</ul>
</div>
I also have the JS and CSS linked:
<link rel="stylesheet" type="text/css" href="http://flexslider.woothemes.com/css/flexslider.css">
<link rel="stylesheet" type="text/css" href="http://lab.mattvarone.com/projects/jquery/totop/css/ui.totop.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type='text/javascript' src="http://flexslider.woothemes.com/js/jquery.flexslider.js"></script>
<script type='text/javascript' src="http://flexslider.woothemes.com/js/jquery.easing.js"></script>
<script type='text/javascript' src="http://flexslider.woothemes.com/js/jquery.mousewheel.js"></script>
<script type='text/javascript' src="http://lab.mattvarone.com/projects/jquery/totop/js/jquery.ui.totop.js"></script>
Of course its a little bit difficult to say why your code is not working.
Have you checked what #Html.Raw(item["newsimage"]) returns ?
But...
You could use a carousel that runs on bootstrap.
The code below i made is to scan a folder for images and then i send them to the view with a viewbag.
--Controller code Start--
var GetSliderImaged = Directory.EnumerateFiles(Server.MapPath("~/Content/SlideShowIndexPage")).Select(fn => Path.GetFileName(fn));
ViewBag.Sliderimages = GetSliderImaged;
--Controller code End--
--View code Start--
<div id="myCarousel" class="carousel slide MTop10 BRadius10 unselectable" data-ride="carousel" data-interval="6000">
<ol class="carousel-indicators" style="margin-bottom: 0px;">
#{
var ii = 0;
foreach (var image in ViewBag.Sliderimages)
{
if (ii == 0)
{
<li data-target="#myCarousel" data-slide-to="#ii" class="active"></li>
}
else
{
<li data-target="#myCarousel" data-slide-to="#ii"></li>
}
ii++;
}
}
</ol>
<div class="carousel-inner " role="listbox">
#{
var i = 0;
foreach (var image in ViewBag.Sliderimages)
{
if (i == 0)
{
<div class="item active">
<img src="~/Content/SlideShowIndexPage/#image" alt="#image" title="#image" class="img-responsive AWIndexPageSlideImage" />
<div class="carousel-caption">
</div>
</div>
i++;
}
else
{
<div class="item">
<img src="~/Content/SlideShowIndexPage/#image" alt="#image" title="#image" class="img-responsive AWIndexPageSlideImage" />
<div class="carousel-caption">
</div>
</div>
}
}
}
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
--View code End--
Just so you know .. the code is not complete but its works for sure if there are images "It does not check if there are no images in the viewbag etc"
But for sure that will be easy to make it yourself.

How to show Multinode tree picker value on its Parent Node

Hi please need help how to render my multinode tree picker value (http://screencast.com/t/NTu1NqXsTmBz) to show it on its parent node named PORTFOLIO ..
i want the multinode picker value should be placed between the Portfolio and About section (http://screencast.com/t/F0Dnnv9a) but I don't know how yet i tried render it and still not work ..
here is the finish template : screencast.com/t/ar1zeZ43Pf6J
Node tree picker code:
#if (Model.Content.HasValue("mntp_pickContent"))
{
var bannerListValue = Model.Content.GetPropertyValue<string>("mntp_pickContent");
<div id="container" class="container-portfolio">
#foreach (var item in bannerListValue.Split(','))
{
var page = Umbraco.Content(item);
<div class="col-md-4 element branding">
<div class="portfolio-item flip ">
<div class="flip-content">
<div class="front">
<img width="360" height="249" src="#page.Url" class="attachment-project-thumb wp-post-image" alt="background4" />
</div>
<div class="back">
<div class="back-content">
<h4>#page.contentTitle</h4>
<div class="txt-project">
<p>#page.contentsubTitle</p>
</div>
<i class="fa fa-plus"></i> More
</div>
</div>
</div>
</div>
<!-- flip container -->
</div>
}
</div>
}
Parent Node Portfolio.cshtml
#{ if (Model.Content.HasValue("port_backImage"))
{
var bgport = Umbraco.TypedMedia(Model.Content.GetPropertyValue<string>("port_backImage"));
<section class="section-wrap section-portfolio" style="background-image: url(#bgport.Url)" id="portfolio">
<div class="container">
<div class="container-wrap row portfolio">
<div class="container-wrap-title col-md-6">
<h2>#Model.Content.GetPropertyValue("pageTitle")</h2>
<h6>#Model.Content.GetPropertyValue("subTitleText")</h6>
</div>
<div class="container-wrap-subnav col-md-6">
<ul class="subnavigation" id="filters">
<li class="active">show all</li>
#foreach (var portMenu in Model.Content.Children)
{
<li>#portMenu.Name</li>
}
</ul>
</div>
</div>
</div>
</section>
}
}
This all depends on the Templating Engine you are using.
If you are using MVC, then you need to add your MNTP logic to a partial view.
See the following link:
https://our.umbraco.org/documentation/Reference/Templating/Mvc/partial-views
If you are using WebForms, then you will need to add your logic to a Razor file OR alternatively a UserControl (.ascx) file. See the following links:
https://our.umbraco.org/documentation/reference/templating/macros/
https://our.umbraco.org/documentation/reference/templating/macros/Razor/
http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls

Asyc Error on IE protractor

I'm currently trying to test the following pice of code:
<footer class="footer">
<div class="container">
<div class="row">
<form subscribe-directive="" ng-controller="SubscribeController" class="form col-xs-12 col-sm-8 col-md-6 col-lg-4 ng-scope ng-dirty ng-valid ng-valid-email">
<h3 class="footer__title text-uppercase margin-bottom-25">Sign up!</h3>
<div class="row">
<div class="col-sm-8 col-xs-7">
<input type="email" class="form-control ng-touched ng-dirty ng-valid ng-valid-email" ng-disabled="working || subscription.done" placeholder="Email Address" ng-model="subscription.email"> </div>
<div class="col-sm-4 col-xs-5">
<button ng-click="submit(subscription.email)" ng-disabled="working || !subscription.email || subscription.done" ng-class="{'working': working}" class="btn btn--inverse btn-red form-control" type="submit" disabled="disabled"> <span ng-bind-html="submitBtn" class="ng-binding">SUBSCRIBE</span> </button>
</div>
</div>
<p ng-show="callback_message" class="msg ng-binding ng-hide" ng-bind-html="callback_message"></p>
</form>
<nav class="col-xs-12 col-md-6 col-lg-offset-2">
<ul class="nav navbar-nav navbar-right margin-bottom-25">
<li>Press
</li>
<li>News
</li>
<li>Contact Us
</li>
<li><a target="_blank" href="//test.com/en">Test Project</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="footer__social-icon"> <a target="_blank" href="https://www.facebook.com/"><i class="fa fa-facebook"></i></a> </li>
<li class="footer__social-icon"> <a target="_blank" href="https://twitter.com/"><i class="fa fa-twitter"></i></a> </li>
<li class="footer__social-icon"> <a target="_blank" href="https://www.youtube.com/user/"><i class="fa fa-youtube"></i></a> </li>
</ul>
</nav>
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 copy"> Privacy Policy
<br> Copyright © Test-inc. All Rights Reserved. </div>
<div class="col-xs-12 col-sm-6 text-right copy">
<br> Microsoft Ventures. Supported by Microsoft Ventures London Accelerator </div>
</div>
</div>
</footer>
But when I do the following actions:
it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {
browser.executeScript("window.scrollBy(0,10000)");
basePage.email.sendKeys('bruno#test.com');
basePage.subscribe.click().then(function () {
browser.sleep(7000);
basePage.confirmMessage('Contact already added to target campaign');
});
On my basePage I've:
//this.email = element(by.model('subscription.email'));
this.email = element(by.xpath('/html/body/footer/div/div[1]/form/div/div[1]/input'));
this.waitlistBtn = element.all(by.binding('submitBtn'));
this.subscribe = element(by.buttonText('SUBSCRIBE'));
I keep getting the follwing error (I'm running it against BrowserStack):
Failures:
1) New Landing page module verification --> User should be correctly added to the update list
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at Timer.listOnTimeout (timers.js:110:15)
Here's my part of my configuration:
{
name: testName,
browserName: 'IE',
browser_version: '11.0',
os: 'Windows',
os_version: '8.1',
resolution: '2048x1536',
'browserstack.user': browserstackUser,
'browserstack.key': browserstackKey,
'browserstack.debug': 'true',
'browserstack.selenium_version': '2.45.0',
'browserstack.ie.driver': '2.44',
ignoreProtectedModeSettings: true
}
onPrepare: function () {
jasmine.getEnv().addReporter(reporter);
browser.driver.manage().window().maximize();
global.dvr = browser.driver; //variable to call selenium directly
global.isAngularSite = function (flag) {
browser.ignoreSynchronization = !flag; //This setup is to configure when testing non-angular pages
};
//browser.manage().timeouts().pageLoadTimeout(90000);
browser.manage().timeouts().implicitlyWait(100000);
}
I must clarify that it does not happen with other test for IE, it just happens with this part that's located at the footer of the page.
Can you please help? do you have any suggestion? or what can you see that I'm doing wrong?
Thanks.-
Since I had many problems to avoid the ASync, I've decided that for this particular scenario to avoid IE! I've done the following:
it('User should see a message that he has already been added to the campaing when entering the same email twice', function () {
browser.getCapabilities().then(function (capabilities) {
browser = capabilities.caps_.browserName;
platform = capabilities.caps_.platform;
}).then(function () {
console.log('Browser:', browser, 'on platform', platform);
if (browser == 'internet explorer') {
console.log('IE Was avoided for this test.');
} else {
basePage.email.sendKeys('bruno#test.com');
console.log('Mande el mail');
basePage.subscribe.click().then(function () {
basePage.confirmMessage('Contact already added to target campaign');
});
}
});
});
Please, if anyone reading this comes up with a better solution, please post.

Resources