I have same button like Save & Close on different tab in my application. If I write XPath like //button[contains(text(), 'Save')] it shows result for all button with 'Save' text present on different tab either active or inactive. Is there any way to get result for 'Save' button only for currently opened active tab?
These are HTML for 'Save' button for different places. I want to write one XPath which should work for all 'Save' button so that I can use it in a method. Wanted to know is there any way to get result for presently opened tab?
1)
<button class="btn ng-binding btn-primary" style="margin-right:5px;" ng-class="checkDeleteCrud()" ng-click="modalActionManager()" ng-disabled="disableSaveButton()" ng-hide="crudStatus==='V'" type="button" aria-hidden="false">Save
</button>
2)
<button class="btn ng-binding btn-primary" ng-class="checkDeleteCrud()" ng-click="modalActionManager()" ng-disabled="( notValidType() || locksavebutton || !createStatisticsForm.$dirty ) && saveButtonText=='Save' " ng-hide="crudStatus==='V'" type="button" aria-hidden="false">
Save
</button>
3)
<button class="btn ng-binding btn-primary" style="margin-right:5px;" ng-class="checkDeleteCrud()" ng-click="modalActionManager()" ng-disabled="disableSaveButton()" ng-hide="crudStatus==='V'" type="button" aria-hidden="false">Save
</button>
If you are looking for something generic for visible button why not simply go with CSS Selector like :
button[ng-disabled*=' ']
If I explain currently all your disabled elements have ng-disabled value equal to disableSaveButton() but the active element doesn't have this function but contains data with spaces so I will look in any spaces within button ng-disabled data simple.
Hope this helped.
First look for the active tab, for this you need to know how the active tab in the Dom differs from non-active tabs. Then look in this element for a button with the text "Save". Use a dot as the first character in your XPath expression.
Let say webelement "tab" is the active tab then you can find the button as follows (C# code):
tab.FindElement(ByXPath(".//button[contains(text(),'Save')]")
Related
Q. Same kind of class applied to all Download button,How to distinct them from each other? Let's say i want to click on 3rd number of download button. Find a xpath for that button.
I have tried this but it's common for all.
//div[#class='statement-download']
<div class="statement-download">
<button class="btn btn-sm btn-icon btn-outline btn-default mb-0" type="button">
<i class="mdi mdi-download m-r-5"></i>
<span>Download</span>
</button>
</div>
use the index of the parent div.
//div[#class='statement-card'][3]/div[#class='statement-download']
For 3rd, try following xpath:
(//div[#class='statement-download'])[3]
You can use the date as a starting point
date = 'July 2048'
//div[.='{date}']/following-sibling::div[#class='statement-download']
It's a better way you can do it by using loops if you have multiple operations
List<WebElement> statementdownload =
driver.findElements(By.xpath("//div[#class='statement-download']"));
for (int i=0;i<statementdownload.size();i++) {
statementdownload.get(i).click();
statementdownload.get(i).getText();
// You can use your condition here
}
I have button in our website, and border areas of the button is not clickable. So, i need to make sure the button is getting clicked at the center. Is it possible via selenium?
I tried using coorinates, but it is not recommended for our scenario.
xpath used : //div/button[#id='clickme']
<div class="col-lg-10 col-sm-12 p-0 pt-4">
<button class="click mb-3 " tabindex="0" id="clickme">+ Click Here</button>
</div>
Java code used to click
WebElement button = driver.findElement(By.id("clickme"));
button.click();
I guess the click is happening sometimes[2 out of 10 times] on the border where it is not clickable(hand symbol not shown) . As a result report says the click action happened, but there is no event fired on the website.
To identify the element with text as Click Here you can use either of the following Locator Strategies:
cssSelector:
"button.click#clickme"
xpath:
"//button[contains(#class, 'click') and #id='clickme'][contains(., 'Click Here')]"
on whom I am able to click, on clicking , nothing happens, i.e. the action is disabled. However, a tooltip gets displayed. The tooltip appears only when we focus on the button.
The html of the button is as follows:
<button type="button" style="color:#ffffff;" rel="rel-517347" data-toggle="popover" data-animation="true" data-placement="top" data-html="true" data-trigger="hover" data-content="<span class='text-center'>
<div>Ride can only be edited before </div><div>1 hour of pickup time.</div>
</span>" class="btn btn-default disbleBtn width_100" data-original-title="" title="">Edit Ride</button>
where Ride can only be edited before is the tooltip.
How can i verify the text of the tooltip as it keeps getting destroyed.
Note that isEnabled() function returns true here as i can click on the button, but no action takes place.
Is there any way I can verify the class of the button i.e btn btn-default disbleBtn width_100 ?
Is there any function or method for it?
I supposed you need to hover not click on the button. When hover tooltip is showing and than you click immediately and tooltip gone.
Do it manually with chrome devtools, open devtools-> sources tab, hover on the button and press F8 to pause then inspect tooltip element. After you get selector for tooltip try codes below:
new Actions(driver).moveToElement(buttonElement).perform();
String tooltipText = new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(toolTipLocator).getText();
//Verify
Or try this:
new Actions(driver).moveToElement(buttonElement).perform();
new WebDriverWait(driver, 10)
.until(ExpectedConditions.textToBePresentInElementLocated(toolTipLocator, textToVerify)
ID and Xpath is changing for "OK" button every time while saving(Account).
HTML Code:
<div class="modal-footer" style="display: block;">
<div class="bootstrap-dialog-footer">
<div class="bootstrap-dialog-footer-buttons">
<button id="fe02d6bd-6058-4871-b0e1-c1e914f64a6a" class="btn btn- default">Ok</button>
</div>
</div>
</div>
</div>
Xpath:.//*[#id='fe02d6bd-6058-4871-b0e1-c1e914f64a6a']
"ID"/XPath is not constant and it is varying while saving.
use the below code:
driver.findElement(By.cssSelector("div.bootstrap-dialog-footer-buttons>button.btn.btn-default"));
You can devise your own XPath locator to find the OK button by it's text content like so:
//button[.='Ok']
The first part of the XPath expression - //button - will select all <button> WebElements within the currently focused content.
The second part - [.='Ok'] - is a predicate that will filter out any WebElements whose exact text content is not equal to 'Ok'.
If it is the only OK button available on the page then you can probably use below code.
driver.findElement(By.xpath("//button[contains(.,'Ok')]"));
Else you can take a reference of parent window and locate a button on it as below
WebElement modalWin = driver.findElement(By.id("modal-window-id"));
modalWin.findElement(By.xpath("//button[contains(.,'Ok')]"));
This below code helps to click OK button in any page.
just call this method with parameter saying OK
public void buttonClick(String buttonname){
WebElemennt button = driver.findelement(by.xpath("//button[text(),'Ok']"))
or
WebElemennt button = driver.findelement(by.cssselector(".btn btn- default"))
for(int i=0; i<button.size;i++)
{
if(button.get(i).gettext().equalIgnorecase(buttonname))
{
button.get(i).click
}
}
}
Let me know result..
What happened: I have a page where user has to click on a button and selection is displayed in modal. When they clicked on what ever they wanted div element on the page is updated, via AJAX, which shows what they have selected and has an option "view item".
I have defined that "view item" should open up another modal view which will have all the information on the item, and now, referring to the above paragraph, rather then opening modal view user is being transferred to that page?
Question:
Is their a walk around for modal to be activated on the elements that were loaded after document load stage?
Example code: On initial load user is presented with following code, at this example item was set prior to load:
<div id="dynamic-area">
Item 1
view selection
</div>
<input type="radio" name="selection" id="selection" value="" data-toggle="modal" data-remote="/selection/search/1" />Change selection
When user have picked a different item after clicking on "change selection" #dynamic-area was fully updated with a data that was fetched via AJAX on the selected item.
So lets say, if user have picked item 3, we would have code below:
<div id="dynamic-area">
Item 3
view selection
</div>
<input type="radio" name="selection" id="selection" value="" data-toggle="modal" data-remote="/selection/search/1" />Change selection
Now if user to click on the "view selection", user is being to the page 'selection/view/3' when user should see modal.
After extending this function action worked as it should