I have two objects on the page with same html. Only one of the element's parent tag doesn't have same class name. When I try using not(contains()) it still shows both elements
below is the xpath I tried and still it is detecting both buttons and always clicking on the second button.
//div[contains(#class,"jss") and
not(contains(#class,"canvas-image-export"))]//button[contains(.,'Connected')]
below is the code for first button named Connected where I am interested to get
<div class="jss203">
<div class="MuiTabs-root jss244">
<div class="MuiTabs-scroller MuiTabs-fixed" style="overflow: hidden;">
<div class="MuiTabs-flexContainer" role="tablist">
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary Mui-selected" tabindex="0" type="button" role="tab" aria-selected="true"><span class="MuiTab-wrapper">Overview</span><span class="MuiTouchRipple-root"></span></button>
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary" tabindex="-1" type="button" role="tab" aria-selected="false"><span class="MuiTab-wrapper">Data Sources</span><span class="MuiTouchRipple-root"></span></button>
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary" tabindex="-1" type="button" role="tab" aria-selected="false"><span class="MuiTab-wrapper">Connected</span><span class="MuiTouchRipple-root"></span></button>
</div>
</div>
</div>
</div>
below is the code for second button named Connected which I should not click on
<div class="jss197 canvas-image-export">
<span class="" data-testid="componentContainer">
<div class="MuiTabs-root jss244">
<div class="MuiTabs-scroller MuiTabs-fixed" style="overflow: hidden;">
<div class="MuiTabs-flexContainer" role="tablist">
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary Mui-selected" tabindex="0" type="button" role="tab" aria-selected="true"><span class="MuiTab-wrapper">Overview</span><span class="MuiTouchRipple-root"></span></button>
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary" tabindex="-1" type="button" role="tab" aria-selected="false"><span class="MuiTab-wrapper">Data Sources</span><span class="MuiTouchRipple-root"></span></button>
<button class="MuiButtonBase-root MuiTab-root MuiTab-textColorPrimary" tabindex="-1" type="button" role="tab" aria-selected="false"><span class="MuiTab-wrapper">Connected</span><span class="MuiTouchRipple-root"></span></button>
</div>
</div>
</div>
</span>
</div>
TIA
Your problem here is that you are looking on the upper parent node <div class="jss197 canvas-image-export"> vs <div class="jss203"> while there is another element there <div class="MuiTabs-root jss244"> or <div class="MuiTabs-root jss244"> and it is also matching your XPath //div[contains(#class,"jss") and not(contains(#class,"canvas-image-export"))]//button[contains(.,'Connected')].
So, to make your XPath work you need to add one more detail: not contains MuiTabs-root class, as following:
//div[contains(#class,"jss") and not(contains(#class,"canvas-image-export")) and not(contains(#class,"MuiTabs-root"))]//button[contains(.,'Connected')]
To get only first div buttons, you can exclude the span tag for the second element. Using following xpath you can get that.
//div[starts-with(#class,'jss')][not(span[#data-testid='componentContainer'])]//button[contains(.,'Connected')]
Or
//div[starts-with(#class,'jss')][not(span)]//button[contains(.,'Connected')]
Related
Want to obtain the xpath for the elements from a drop-down menu (refer the image),
Tried with the following,
.//div[#class='styles__dropDownList___1PunQ styles__dropDownList___2fbeV'] with this only the drop down is getting selected
No luck with,
.//div[#class='styles__dropDownList___1PunQ styles__dropDownList___2fbeV' and data-test-id='option_0']
//div[#class='styles__dropDownList___1PunQ styles__dropDownList___2fbeV' and text()='Hyg']
//div[#class='styles__dropDownList___1PunQ styles__dropDownList___2fbeV' and contains(#text,'Hyg')]
Element Section:
<div class="dd-menu-items">
<ul class="dd-items-center">
<div class="styles__dropDownList___1PunQ styles__dropDownList___2fbeV">
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_0" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Hyg</div>
</div>
</div>
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_1" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Kay</div>
</div>
</div>
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_2" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Kay</div>
</div>
</div>
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_3" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Perio</div>
</div>
</div>
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_4" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Smiles</div>
</div>
</div>
<div class="styles__optionListItem___1SA75" role="button" data-test-id="option_5" tabindex="0">
<div class="styles__optionDiv___o55ex">
<div>Smiles</div>
</div>
</div>
</div>
</ul>
</div>
To click the desired element you should first open the dropdown box by clicking on it and after that to click on the element.
Since you can select it uniquely only according to the text the element contains you should use //div[contains(text(),'Hyg')] or //div[text()='Hyg']
In my blazor webassembly app, I'm using bulma dropdown component and I have Log out button inside togglable dropdown content.
Here is the html of my Log out button.
<div id="userMenu" class="dropdown is-right #(UserMenuCollapsed ? "is-active" : null)" #onclick="ToggleUserMenu" #onfocusout="FocusOutHandler">
<div class="dropdown-trigger p-1">
<button class="bg-green-300 rounded-full h-10 w-10 flex items-center justify-center border-none cursor-pointer" aria-haspopup="true" aria-controls="user-menu">AR</button>
</div>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content">
<NavLink href="/profile" Match="NavLinkMatch.All" class="dropdown-item">
Profile (#context.User.Identity.Name)
</NavLink>
<hr class="dropdown-divider">
<button class="dropdown-item" #onclick="BeginSignOut">Log out</button>
</div>
</div>
</div>
This piece of html get displayed when I click #userMenu div element. Now when I click Log out button nothing happens.
On googling I found like sometime changing #onclick to #onmousedown will make click action to work. I changed and it got worked. But not sure why. Please can anyone explain what happens under the hood?
Update 1:
After reading #Umair comments, I have tried to use event stop propagation but that doesn't seem to work.
Here is the updated code:
<div id="userMenu" class="dropdown is-right #(UserMenuCollapsed ? "is-active" : null)" #onclick="ToggleUserMenu" #onfocusout="FocusOutHandler">
<div class="dropdown-trigger p-1">
<button class="bg-green-300 rounded-full h-10 w-10 flex items-center justify-center border-none cursor-pointer" aria-haspopup="true" aria-controls="user-menu">AR</button>
</div>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content">
<NavLink href="/profile" Match="NavLinkMatch.All" class="dropdown-item">
Profile (#context.User.Identity.Name)
</NavLink>
<hr class="dropdown-divider">
<button class="dropdown-item" #onclick="BeginSignOut" #onclick:stopPropagation="stopPropagation">Log out</button>
</div>
</div>
</div>
#code {
private bool stopPropagation = false;
}
So I'm trying to bind the click event so it only runs when the actually href title is clicked on. here is my code.
<collapse :multiple-active="false">
<div v-for="(campaign, index) in allCampaigns" :key="index">
<collapse-item :title="campaign.campaign_name" #click.native.prevent="grabClientFacebookData(campaign.id)">
<div v-if="spinner == true" style="text-align: center"><img src="../../../../img/spinner.gif"></div>
<div v-if="search == true">
<vue-good-table
:columns="columns"
:rows="tableData"
styleClass="vgt-table striped bordered"/>
<highcharts :options="chartOptions"></highcharts>
</div>
</collapse-item>
</div>
</collapse>
And here is the parent element:
<div class="card card-plain">
<div role="tab" id="headingOne" class="card-header">
<a data-toggle="collapse"
data-parent="#accordion"
:href="`#${itemId}`"
#click.prevent="activate"
:aria-expanded="active"
:aria-controls="`content-${itemId}`">
<slot name="title" #click.prevent="grabClientFacebookData(campaign.id)">
{{title}}
</slot>
<i class="now-ui-icons arrows-1_minimal-down"></i>
</a>
</div>
<collapse-transition :duration="animationDuration">
<div v-show="active"
:id="`content-${itemId}`"
role="tabpanel"
:aria-labelledby="title"
class="collapsed">
<div class="card-body">
<slot></slot>
</div>
</div>
</collapse-transition>
I am fairly new to vue and was wondering if it's possible. My problem is that the click event shoots whenever any port of the collapse is clicked, not just the title.
have you tried wrapping {{title}} in a span with the event bound to that? i.e.
<span #click.prevent="grabClientFacebookData(campaign.id)">{{title}}</span>
I made my website menu like this:
<div class="container-fluid">
<div class="row">
<nav id="menu">
<div class="col-sm-12 col-md-2 active-link">
<div class="vertical-align" >
<img class="img-responsive" src="img/logo.png" alt="logo">
</div>
</div>
<div class="col-sm-3 col-md-2 nonactive-link">
<div class="vertical-align" >
MENU<br>ONE
</div>
</div>
<div class="col-sm-3 col-md-2 nonactive-link">
<div class="vertical-align" >
MENU<br>TWO
</div>
</div>
<div class="col-sm-2 col-md-2 nonactive-link">
<div class="vertical-align" >
MENU THREE
</div>
</div>
<div class="col-sm-2 col-md-2 nonactive-link">
<div class="vertical-align" >
MENU FOUR
</div>
</div>
<div class="col-sm-2 col-md-2 nonactive-link">
<div class="vertical-align" >
MENU FIVE
</div>
</div>
</nav>
</div>
</div>
Im not using original nav from bootstrap that is a list (ul li ..)
is there a way i can achive the toggle menu using just divs with col-xs-12 ?
How can i put my code to achieve that just using divs whit col's?
Thanks a lot :)
In order to actually make it a nav menu you need some bootstrap utility classes on the most parent nav element <nav class="navbar navbar-default"> and then you need to add the menu "three lines" icon HTML
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
Then you need to add some more utility classes and ID to the wrapper of the actual nav links <div class="collapse navbar-collapse" id="navbar-collapse"> with making sure the id matches the data-target in the nav button itself.
The bootstrap doc on this is HERE
Also I made a JSFIDDLE with your original HTML and modified it, let me know if that makes sense.
I have following HTML code snippet:
<div class="pagging-box status-border status-border">
<div class="left-container">
<div>
<div class="clientid-hover">
<h4>AAB52</h4>
<div class="hover-title" style="display: none;">
<p>AAB52</p>
</div>
</div>
<div class="clientid-hover-state pl-info">
<h4>CO</h4>
</div>
<div class="client-name-hover">
<h4>Daniel-old Polar-old</h4>
</div>
<p class="contacting-client">Interview Partially Co..</p>
</div>
</div>
<div class="right-container">
<div class="start-session pull-right">
<a href="javascript:void(0)");" class="login-button">
<i class="fa fa-2x fa-play-circle continue-session"></i>
</a>
</div>
</div>
</div>
I want to locate the Anchor tag on the basis of <h4>AAB52</h4> text. I have tried to locate the same with siblings like following xpath
//div[h4[contains(. , "AAB56")]]/following-sibling::div[1]
(xpath is not correct as it is locating second one div immediate of AAB52 text )
following-sibling operates on the parent of the context node, so you first need walk up to the correct context node:
//h4[. = 'AAB52']/../../../following-sibling::div[1]/div/a
Alternatively you can use:
//div[./div/div/h4 = 'AAB52']/following-sibling::div[1]/div/a