I tried the following code below to click drop down:
driver.FindElement(By.XPath("//div[#id='content']/div/app-appdashboard/div[3]/div/div/div/div/button")).Click();
And I tried the following code to click on one of options from drop down:
driver.FindElement(By.XPath("//div[#id='cdk-overlay-0']/div/div/button[16]/span")).Click();
<button _ngcontent-jco-c9="" aria-haspopup="true" class="btn btn-state dropdown-toggle" mat-button="" ng-reflect-menu="[object Object]">
<span _ngcontent-jco-c9="" class="ng-star-inserted"> Update Overall App Status </span></button>
<button _ngcontent-jco-c9="" aria-label="option row button." class="menu-button mat-menu-item ng-star-inserted" mat-menu-item="" role="button" tabindex="0" ng-reflect-role="button" name="PM Supervisor Approved" title="PM Supervisor Approved" aria-disabled="false"><span _ngcontent-jco-c9="">PM Supervisor Approved</span><div class="mat-menu-ripple mat-ripple" matripple="" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLButtonElement]"></div></button>
Try this:
WebDriverWait wait=new WebDriverWait(driver, 20);
driver.FindElement(By.className("ng-star-inserted")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//button[#name='PM Supervisor Approved']/span")));
driver.FindElement(By.xpath(".//button[#name='PM Supervisor Approved']/span")).click();
Related
in my website which is done in bootstrap, there is a mobile menu, then menu is like below:
<a class="nav-link" href="#" id="shop_submenu" role="button" data-bs-toggle="dropdown" aria-expanded="true" data-bs-auto-close="true">
Rent Costumes
</a>
when user clicks on it, it expands and shows the items inside it. When you inspect it you can see a class 'show' is added and when u click it again the class is removed and it should close:
<a class="nav-link show" href="#" id="shop_submenu" role="button" data-bs-toggle="dropdown" aria-expanded="true" data-bs-auto-close="true">
Rent Costumes
</a>
however its not closing, can anyone please tell me how to close it when user clicks on it again.
this is my live url:
enter link description here
, thanks in advance
which version u used.in bootstrap5 we use data-bs-toggle.otherwise its data-toggle.go thru this https://www.w3schools.com/bootstrap4/bootstrap_dropdowns.asp#:~:text=To%20open%20the%20dropdown%20menu,actually%20build%20the%20dropdown%20menu.
...
Rent Costumes
</a>
i guess you'r using bootstrap4.hope ds helps.https://www.w3schools.com/bootstrap4/bootstrap_dropdowns.asp
i have found an alternate solution for this, i used javascript to check even and odd clicks on the button and changed the style of the submenu accordingly, below is the code:
function myFunction() {
let even = 'block';
let odd = 'none';
let elements = document.getElementsByClassName("dropdown-menu")
Array.prototype.forEach.call(elements, function(element) {
element.style.display === even ? element.style.display = odd : element.style.display = even
});
}
<a class="nav-link" href="#" id="shop_submenu" onclick="myFunction()" role="button" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="true">
Rent
</a>
I am dynamically creating a html link and I want to set a onclick event with a parameter. Parameters is variable.
return '<a role="button" href="#" class="btn btn-default btn-sm delete-btn ml-2" onclick="deleteMeeting('+data[1]+')" >Delete</a>'
I am getting an error,
Uncaught SyntaxError: missing ) after argument list.
Currently it render like this,
<a role="button" href="#" class="btn btn-default btn-sm delete-btn ml-2" onclick="deleteMeeting(Junior Technical Author)">Delete</a>
The problem is you are outputing a string directly into a function call without using '. You need to add escaped ' and place your data[1] inside them.
return '<a role="button" href="#" class="btn btn-default btn-sm delete-btn ml-2" onclick="deleteMeeting(\''+data[1]+'\')" >Delete</a>'
This way, you will paste your data[1] inside a string.
I am working with angular. When I click a button, I get a dropdown with some choices. How can I change the button image or button and text when I click on it? The goal is for it to return to its original state when it is clicked again.
I leave the image here to understand better.
The button in my case will be an image.
What I want is this: I click the button and open the dropdown, in that dropdown, when I click Start, I want the image of the button to be changed (or the button) and Start to be Pause. If you do the same again, the opposite happens ... that is, if you have Pause, pressing it changes the button and Pause becomes Start.
It is possible? Can anyone help me?
Example, my code
Codepen
HTML
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<img src="">
</button>
<div class="dropdown-menu">
<a class="dropdown-item">Start</a>
<a class="dropdown-item">Add new</a>
</div>
</div>
I am working with angular, if anyone can help me get the solution using their resources, I really appreciate
Use a variable to store the current state and toggle view using it's value.
app.component.ts :
currentState : string = 'pause'
app.component.html :
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<!-- Image is to be shown by default -->
<img src="1.png" *ngIf="currentState=='pause'"">
<!-- Image is to be shown on clicking start -->
<img src="2.png" *ngIf="currentState=='start'"">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngIf="currentState=='pause'" (click)="currentState='start'">Start</a>
<a class="dropdown-item" *ngIf="currentState=='start'" (click)="currentState='pause'">Pause</a>
</div>
</div>
add a function to onChange and do it there,
<div class="dropdown">
<button (change)="changeImg()" type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<img src="{{imgSrc}}">
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngIf="isStarted">Start</a>
<a class="dropdown-item" *ngIf="!isStarted">Pause</a>
<a class="dropdown-item">Add new</a>
</div>
</div>
in ts,
isStarted:boolean = false; // default to pause
imgSrc:any;
changeImg(){
// We can even write the simplest code instead the below line.
// isStarted = false ? true : false;
isStarted = !isStarted;
imgSrc = isStarted ? startImageSrc : pauseImageSrc;
}
hope this works, did not test :)
Here is my HTML for angular 2 applications. I am executing my tests in Chrome.
<div _ngcontent-c0="" class="header-actions">
<!---->
<clr-dropdown _ngcontent-c0="" class="dropdown" style="position: static;">
<button _ngcontent-c0="" class="nav-text dropdown-toggle"
clrdropdowntrigger="">
<span _ngcontent-c0="">User Name</span>
<!---->
</button>
<!---->
</clr-dropdown>
</div>
I have tried the following options, but failed to click on User Name
1.1 element(by.css('nav-text dropdown-toggle')).click();
1.2 element(by.css('.nav-text dropdown-toggle')).click();
1.3 element(by.css("//span[. = 'User Name']")).click();
1.4 element(by.xpath("//span[. = 'User Name']")).click();
2. var logUser = $("div.header-actions clr-dropdown.dropdown button span"),
EC = protractor.ExpectedConditions;
browser.wait(EC.visibilityOf(logUser), 5000);
logUser.click();
3. var elementToClick = element(by.css('.btn btn-lg btn-primary btn-block'));
browser.wait(protractor.ExpectedConditions.elementToBeClickable(elementToClick)
,10000).then ( function () {elementToClick.click(); });
Any Help is appreciated.
I think there is an problem with your css selector.
try this, this should work.
element(by.css('div.header-actions > clr-dropdown.dropdown > button.nav-text')).click();
I need to click an Add button.I have traversed to the page having the Button,as verified from Response data in View Results Tree.
I tried making a get request (post button click URL)but that didn't work.
Below is the HTML of the Button
<button
class="bigbutton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
onclick="var win = this.ownerDocument.defaultView || this.ownerDocument.parentWindow; if (win == window) { window.location.href='?x=KOGI5TeEN-U*JE6roI7oZMd-OfKSr5oQnRTh7tHdN*Bh66LwE2vEHDjxo9WFuOf7Ti2zcBh-IaE'; } ;return false"
style="float: right;"
role="button"
aria-disabled="false">
<span class="ui-button-text"> Add </span>
You need to record the requests to see exactly what kind of requests are generated by your application.
Follow this tutorial to understand how to go about it.
http://jmeter.apache.org/usermanual/jmeter_proxy_step_by_step.pdf