selenium wrong xpath with li c# - c#

var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.favorit.com.ua/uk/live/");
string myTime = driver.FindElement(By.XPath("/html/body/div[#class='wrapper']/" +
"div[#class='contentdiv']/" +
"div[#id='middle']/" +
"div[#id='container']/" +
"div[#id='content']/" +
"div[#class='content clear-block bet_a_c']/" +
"div[#id='livediv']/" +
"div[#class='selected--sport--block']/" +
"div[#class='view-wrapper']/" +
"ul[#class='sport--list']/" +
"li[#class='sport--block']/" +
"ul[#class='category--list--block']/" +
"li[#class='category--block sp_1']/" +
"ul[#class='events--list']/" +
"li['']/" +
"ul[#class='event--head-block']/" +
"div[#class='event--head']/" +
"div[#class='event--short--info']/" +
"div[#class='time--block']/" +
"div[#class='headerdiv']/" +
"div[#class='event--timer']")).GetAttribute("innerHTML");
Console.WriteLine(myTime);
Console.ReadLine();
Hello everybody. I just started to learn selenium and collided with the issue of finding an element. I want to get the value of the timer, but it is unsuccessful. I bet my problem is that I am making mistake in XPath at line
"li['']/" +
Do you have an idea how can I get it in a correct way?
I am going to get value '45:00'
from <div class="event--timer">45:00</div>
Oh, by the way when I start debugging my project Chrome browser starts twice. I don't know why, but it happens each time.
Thank you in advance for any suggests.
<body class="tm_18 uk " data-gr-c-s-loaded="true" style="">
<noscript>
<div id="noscript">Будь ласка, увімкніть JavaScript у вашому браузері!</div>
</noscript>
<a id="topsite" name="topsite"></a>
<div id="dialog" title=""></div>
<div id="dialogPre">
<!-- react-empty: 1 -->
</div>
<div id="full_vers" style="display:none;">
<button class="close" rel="fullcls">close</button>
<div class="full_blok">
<p>
Вы перешли на полную версию сайта.
Хотите запомнить Ваш выбор для следующего посещения сайта?
<button rel="fullyes" class="btn-chs">Так</button>
<button rel="fullno" class="btn-chs">Ні</button>
</p>
</div>
<div class="cl"></div>
</div>
<div class="wrapper">
<div class="header">
<div class="headerdiv">
<div class="logo">
<img src="./Фаворит спорт - Зробити ставку. Компанiя_files/blank.gif" alt="" id="logo">
</div>
<div id="counterPl" class="counter--playing" style="display:none;"></div>
<div class="head--block">
<div class="nav--block" style="overflow: visible;">
<ul class="nav--level--1">
<li>
<a href="https://www.favorit.com.ua/uk/bets/" class="service_id_1">
<span class="">СПОРТ</span>
</a>
<button class="sub--level--yes"><i class="fa fa-caret-down"></i></button>
<ul class="nav--level--2">
<li>
<a href="https://www.favorit.com.ua/uk/bets/results/" class="service_id_1">
<span class="">Результати</span>
</a>
</li>
<li>
<a href="javascript:openPopup('12345','http://stats.betradar.com/s4/?clientid=509&language=ukr');" class="service_id_1">
<span class="">Статистика</span>
</a>
</li>
</ul>
<div id="vip-dropdown">
<!-- react-empty: 1 -->
</div>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/live/" class="service_id_1 active">
<span class="">Live</span>
<b>159</b></a>
<button class="sub--level--yes"><i class="fa fa-caret-down"></i></button>
<ul class="nav--level--2">
<li>
<a href="https://www.favorit.com.ua/uk/live/calendar/" class="service_id_1">
<span class="">Календар Live</span>
</a>
</li>
<li>
<a href="javascript:openPopup('123459','http://ls.betradar.com/ls/livescore/?/favoritbetua/ukr/page');" class="service_id_1">
<span class="">Результати Live</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/page/favoritsporttv/" class="service_id_1">
<span class="">Прямі трансляції</span>
</a>
</li>
</ul>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/page/virtual/" class="service_id_1">
<span class="">Віртуальний спорт</span>
</a>
<button class="sub--level--yes"><i class="fa fa-caret-down"></i></button>
<ul class="nav--level--2">
<li>
<a href="https://www.favorit.com.ua/uk/vfl/" class="service_id_1">
<span class="null">Віртуальна футбольна ліга</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/ncup/" class="service_id_1">
<span class="">Кубок націй</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/vto/" class="service_id_1">
<span class="">Віртуальний теніс</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/vbl/" class="service_id_1">
<span class="">Віртуальний баскетбол</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual-games/?category_id=36334" class="service_id_1">
<span class="new">Конячі перегони</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual-games/?category_id=36335" class="service_id_1">
<span class="new">Футбол</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual-games/?category_id=36338" class="service_id_1">
<span class="new">Коняча Рулетка</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual-games/?category_id=36339" class="service_id_1">
<span class="new">Настільний теніс</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=1559" class="service_id_1">
<span class="">Віртуальний футбол</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/virtual/" class="service_id_1">
<span class="new">Віртуальний спорт від Inspired</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=35937" class="service_id_1">
<span class="">Віртуальні Мотогонки</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=35938" class="service_id_1">
<span class="">Віртуальні Велоперегони</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=35939" class="service_id_1">
<span class="">Віртуальні Скачки</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=35941" class="service_id_1">
<span class="">Віртуальні Собачі перегони</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/virtual/?category_id=36097" class="service_id_1">
<span class="">Віртуальна Формула 1</span>
</a>
</li>
</ul>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/casino/" class="service_id_1">
<span class="new">Казино</span>
</a>
<button class="sub--level--yes"><i class="fa fa-caret-down"></i></button>
<ul class="nav--level--2">
<li>
<a href="https://www.favorit.com.ua/uk/page/casino/cashrace/" class="service_id_1">
<span class="new">Гонка призових</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/page/casino/rating/" class="service_id_1">
<span class="">Рейтинг</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/page/casino/winners/" class="service_id_1">
<span class="">Переможці</span>
</a>
</li>
</ul>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/live-casino/" class="service_id_1">
<span class="">Казино LIVE</span>
</a>
<button class="sub--level--yes"><i class="fa fa-caret-down"></i></button>
<ul class="nav--level--2">
<li>
<a href="https://www.favorit.com.ua/uk/page/live-casino/tips-and-strategy/" class="service_id_1">
<span class="">Поради та Стратегія</span>
</a>
</li>
</ul>
</li>
</ul>
<button class="menu_button">
<div class="toggle_switch"><span></span><span></span><span></span></div>
</button>
<ul class="nav-dop-menu">
<li>
<a href="https://www.favorit.com.ua/uk/tvloto/" class="service_id_1">
<span class="">ТВ ЛОТО</span>
</a>
</li>
<li>
<a href="https://www.favorit.com.ua/uk/page/main_promo/" class="service_id_1">
<span class="">Акції</span>
</a>
</li>
</ul>
</div>
</div>
<div class="user--block">
<script id="usermessagewc" type="text/x-jsrender">
<div class="u_msg_tci">
Total critical/important messages <span rel="count">0</span>
</div>
<div class="u_msg_txt">
[[:text]]
</div>
</script>
<script id="usermessage" type="text/x-jsrender">
<div class="u_msg_dt">[[:dt_sesent]]</div>
<div class="u_msg_bl">
<div class="u_msg_subject">[[:subject]]</div>
<div class="u_msg_bd">[[:message]]</div>
</div>
</script>
<div id="user-block">
<div data-reactroot="" class="loginbgL">
<div class="loginbgR">
<div class="loginicon">
<div id="nauth">
<div class="not_login">
<a class="loginpagecl but-blue-1"><span>Увійти</span></a>
<div class="but-red-1" rel="mdlreg"><span>Реєстрація</span></div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<script src="./Фаворит спорт - Зробити ставку. Компанiя_files/loginUser.js.download" type="text/javascript" charset="utf-8"></script>
</div>
</div>
<div class="second--menu">
<div class="settings--block">
<div id="timeplace" class="times_place">
<div data-reactroot="" class="times">
<p>20:20 (UTC +3)</p>
<div></div>
</div>
</div>
</div>
</div>
</div>
<div class="contentdiv">
<div id="middle">
<div id="container">
<div id="content">
<div class="content clear-block bet_a_c">
<div class="badwe" style="display:none;">
<div class="entire">
<div class="close"></div>
<div class="lst-err">
<ul>
<li>Unknown error</li>
</ul>
</div>
</div>
</div>
<div id="scenter"></div>
<div id="video_player"></div>
<div id="video_modal_auth"></div>
<div id="livediv" class="livediv">
<div data-reactroot="" class="selected--sport--block">
<div class="message--widget">
<div class="message--content new--user">
<i class="fa"></i><!-- react-text: 5 -->Новий користувач?<!-- /react-text --><span>Зареєструйтесь</span><b>та отримайте бонус ''Ставка без ризику'' до 500 грн!</b>
</div>
<div class="close--buton"><span>Закрити</span><i class="fa"></i></div>
</div>
<!-- react-empty: 11 -->
<div class="view-wrapper">
<ul class="sport--list">
<li class="sport--block">
<div class="sport--head sp--bg sp_1 head--folding folding--open">
<i class="sporticon sp_1"></i>
<span>
<!-- react-text: 25 -->Футбол<!-- /react-text --><u>83</u>
</span>
<b>Показати все</b>
</div>
<ul class="category--list--block">
<li class="category--block sp_1">
<div class="caterory--head">
<div class="outcomes--name">
<div class="category--name"><i class="sporticon sp--color sp_1"></i><span>Футбол | Іспанія | Ла Ліга</span></div>
<ul class="count--label count-0 outcome-count-3">
<li title="1">1</li>
<li title="X">X</li>
<li title="2">2</li>
</ul>
<ul class="count--label count-1 outcome-count-3 has-param">
<li title="1">1</li>
<li>Фора</li>
<li title="2">2</li>
</ul>
<ul class="count--label count-2 outcome-count-3 has-param">
<li title="Б">Б</li>
<li>Тотал</li>
<li title="М">М</li>
</ul>
<div class="close--category"></div>
</div>
</div>
<ul class="events--list">
<li>
<div class="event--head-block">
<u></u>
<div class="event--head event-has-description">
<div class="event--short--info">
<div class="event--line--position"><span>3371</span><b>1489</b></div>
<div class="time--block">
<div class="event--timer">45:00</div>
</div>
<div class="event--result--type--name">П2</div>
</div>

Can you try with below xpath
"/html/body/div[4]/div[2]/div/div/div/div/div[5]/div/div[2]/ul/li/ul/li/ul/li/div/div/div/div[2]/div"

What about simple //div[#class='event--timer'] ?
string myTime = driver.FindElement(By.XPath("//div[#class='event--timer']")).GetAttribute("innerHTML");

Related

MVC C# Carousel Image

i have been trying to create a carousel image on my MVC application. The below snippet from W3 was just used as an example. The result was the images displayed ont he webpage one below eachother. Do i need to do anything else on the MVC application to resolve this?
<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="Los Angeles" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/newyork.jpg" alt="New york" style="width:100%;">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
I had the same requirement sometime ago and I used below code, look if it works for you.
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
#{
var first = true;
}
#foreach (var item in ViewBag.Images)
{
<div class="carousel-item #(first?Html.Raw("active"):Html.Raw(""))">
<img class="d-block w-100" src="#item.Image" alt="#item.Name">
</div>
first = false;
}
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button"
data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button"
data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Please Try this.I hope your problem is solved
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner" role="listbox">
#{int i = 0;}
#foreach (var item in Model)
{
i++;
var active = i == 1 ? "active" : "";
<div class="carousel-item #active">
<img src="#Url.Content(#item.FilePath)" alt="">
</div>
}
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>

integrating bootstrap classes to have a dropdown list using the Html.ActionLink

trying to make a drop once click on the html action, works with anchor tag
As per below it works with
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#auth" aria-expanded="false" aria-controls="auth">
<p>Testing<span class="dropdown-toggle"></span> </p>
</a>
<div class="collapse" id="auth">
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="pages/samples/login.html"> Home 1 </a></li>
<li class="nav-item"> <a class="nav-link" href="pages/samples/login-2.html"> Home 2 </a></li>
<li class="nav-item"> <a class="nav-link" href="pages/samples/register.html"> Home 3 </a></li>
</ul>
</div>
</li>
working with tag
as per below does not work.\
<li class="nav-item dropdown" id="User">
<i class="fas fa-user-edit " style="margin-left: 30px;margin-top: 6px;"> </i>
#Html.ActionLink("User Management", "Index", "Users", null, new { #class = "nav-link dropdown-toggle", data_toggle = "dropdown", aria_expanded = "false" })
<div class="collapse">
<ul class="nav flex-column sub-menu">
<li>
<a class="nav-link">Home 1</a>
</li>
<li>
<a class="nav-link">Home 2</a>
</li>
<li>
<a class="nav-link">Home 3</a>
</li>
</ul>
</div>
</li>

Creating an active link on a navigation bar while using a master page

I know there are a lot of questions surrounding this topic online however I cannot get any of the solutions to work for me.I have tried numerous way suggested online. I have a master page with my navigation bar code and I want the active link to be highlighted in green when I am on a particular page of the website. I can't figure out what I am doing wrong or missing to get this to work. I am new to ASP.Net and C# so any help would be appreciated.
Here is my current code in body tags of my master page:
<script>
$(document).ready(function () {
var url = window.location;
$('.sidebar .nav').find('.active').removeClass('active');
$('.sidebar .nav li a').each(function () {
if (this.href == url) {
$(this).parent().addClass('active');
}
});
});
</script>
<form id ="form1" runat="server">
<div class="wrapper">
<div class="sidebar" data-color="green" data-image="../assets/img/side-navship.jpg">
<div class="logo">
<a href="Default.aspx" class="simple-text">
Speed-E
</a>
</div>
<div class="sidebar-wrapper">
<ul class="nav">
<li class="">
<a href="<%= Page.ResolveUrl("~/Default.aspx") %>">
<i class="material-icons">dashboard</i>
<p>Home</p>
</a>
</li>
<li class="">
<a href="<%= Page.ResolveUrl("~/NewCert.aspx") %>">
<i class="material-icons">content_paste</i>
<p>New Certificate</p>
</a>
</li>
</ul>
</div>
</div>
<div class="main-panel">
<nav class="navbar navbar-transparent navbar-absolute">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"> </a>
</div>
</div>
</nav>
<div class="content">
<div class="container-fluid">
<asp:ContentPlaceHolder ID="BodyContent"runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
</div>
</div>
</form>

Change <li> class to active when page is loaded

I'm having a hard time to make <li> class to active when page is loaded. Here's my scenario I copied a sample Dropdown in a certain website to integrate it in my website. I'm using C# Asp.Net
_Layout.cshtml
<body>
<div id="header">
#Html.Partial("_HeaderPartial")
</div>
<!--SIDEBAR Navigation-->
<aside id="menu">
// The Dropdown
#Html.Partial("_SidebarPartial")
</aside>
<div id="wrapper">
#RenderBody()
<footer class="footer">
#Html.Partial("_FooterPartial")
</footer>
</div>
<div id="right-sidebar" class="animated fadeInRight">
#Html.Partial("_RightSidebarPartial")
</div>
</body>
_SidebarPartial
<ul class="nav" id="side-menu">
<li>
<span class="nav-label">Dashboard</span>
</li>
<li>
<span class="nav-label">Analytics</span>
</li>
<li>
<span class="nav-label">Interface</span><span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>Panels design</li>
<li>Typography</li>
<li>Colors & Buttons</li>
<li>Components</li>
<li>Alerts</li>
<li>Modals</li>
</ul>
</li>
<li>
<span class="nav-label">App views</span><span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>Contacts</li>
<li>Projects</li>
<li>Project detail</li>
<li>App plans</li>
<li>Social board</li>
</ul>
</li>
<li>
<span class="nav-label">Charts</span><span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>ChartJs</li>
<li>Flot charts</li>
<li>Inline graphs</li>
</ul>
</li>
<li>
<span class="nav-label">Box transitions</span><span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li><span class="label label-success pull-right">Start</span> Overview </li>
<li>Columns from up</li>
</ul>
</li>
</ul>
As I commented, here is a small example with an id attribute on the list:
<ul class="nav" id="side-menu">
<li id="interfaces">
<span class="nav-label">Interface</span><span class="fa arrow"></span>
<ul class="nav nav-second-level">
<li>Panels design</li>
<li>Typography</li>
<li>Colors & Buttons</li>
<li>Components</li>
<li>Alerts</li>
<li>Modals</li>
</ul>
</li>
</ul>
And then you could add the following line to the document.ready function:
$("#interfaces").attr("class", "active");
Check this out. This will also help you
just write the following code inside document.ready function
$('#interfaces').addClass('active');
Cheers

Trying to build dynamic menu from a static one using Templates

I am trying to build, from a static menu, with pre-defined CSS classes into a dynamic one, using the .NET/C# 'Templates', specifically to EPiServer.
Information on PageTree
I am not technical at all, more front end, but been asked to do this project.
Menu code is here.
<ul onClick="" class="zetta-menu zm-effect-fade">
<li style="margin-left: 185px;">
<a href="http://intranet/en/Web-Developments-draft/Marc-Testing/Self-Help/">Self-help
<i class="zm-caret fa fa-angle-down"></i>
</a>
<ul class="w-300">
<li>Email</li>
</ul>
</li>
<li>
<a href="#">Clinical Systems
<i class="zm-caret fa fa-angle-down"></i>
</a>
</li>
<li>
<a href="#">Equipment
<i class="zm-caret fa fa-angle-down"></i>
</a>
</li>
<li>
<a href="#">Training
<i class="zm-caret fa fa-angle-down"></i>
</a>
<li>
<a href="#">Performance
<i class="zm-caret fa fa-angle-down"></i>
</a>
<li>
<a href="#">About us
<i class="zm-caret fa fa-angle-down"></i>
</a>
<ul class="w-300">
<li>Information Governance</li>
<ul class="zm-drop-left w-300">
<li>Drop down</li>
</ul>
</ul>
</li>
</ul>
<br class="clear" />

Categories