Unable to Click on Edit Button , in WebTable - selenium

I am using xpath to click on edit button , but i dont know where the webtable starts so i can click on the webelement.
Below is the link for WebTable.
http://demo.automationtesting.in/WebTable.html
Thanks in Advance.

Try this:
// gets the first edit button
WebElement Edit_btn= driver.findElements(By.xpath("//div[#class = 'avddbl']/button")).get(0);
Actions action = new Actions(driver).doubleClick(Edit_btn);
action.build().perform();

If you want some specific selection e.g. want to edit info of particular user
Then you can use below xpath where you have to changes email address only it will click on the edit icon of that particular record .
//div[text()='steven#hotm.com']/../following-sibling::div//div[#class='avddbl']/button[contains(#class,'btn')]

Related

Selenium XPath for WebTable using parent & sibling

I am trying to automate the web table on the demoqa site https://demoqa.com/webtables where I am aiming to click the edit and delete button for a specific user. Please find the attached screenshot for reference.
Screenshot
I am trying to click the edit and delete button for the user 'Cierra' hence I have created the customize XPath '//div[contains(text(),'cierra#example.com')]//following::div[text()='Insurance']//following::div//div//span[#title='Edit']'
Trying to click the edit and delete button using the contains text with email 'cierra#example.com' however I see four results even I use the unique username. Could anyone help me with this?
(//div[contains(text(),'cierra#example.com')]//following::div[text()='Insurance']//following::div//div//span[#title='Edit'])[1]
you can enclose the result in bracket and call [1] , to get first one:
But you don't have to over complicate it , just get email then go back to parent and get span under that parent ,:
//div[contains(text(),'cierra#example.com')]/..//span[#title="Edit"]
if you still want to use fancy xpath locator then use :
//div[contains(text(),'cierra#example.com')]/following-sibling::div[contains(text(),'Insurance')]/following-sibling::div//span[#title='Edit']

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

How to handle in Automation script when id is same but class name is different

Scenarios is : Click on add button.
Case:
User lands on profile page, then a Loading messsage is displayed , till this message is being displayed the Add button is non-clickable (its id is "add" & class is "btn btnAdd nonclickable") .
When loading message disappears , then Add button is clickable (its ID is "add" & class is "btn btnAdd" ).
I want to automate to click on Add button . But I dont know how much to wait for loading message to complete.
Please help , how can I use class & id locator in this case to automate.
Please reply.
Thanks
Try the below code -
WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[#class='btn btnAdd']")));
driver.findElement(By.xpath("//button[#class='btn btnAdd']")).click();

Unable to right click and select a value using Selenium Webdriver

I need to right click using selenium webdriver. When I right click on the date highlighted in red,I will have a menu opened from where I have to select "Show CTR Impressions Label".
I am able to right click and select "Show Impressions Label" but unable to click it.
Here is my code:
string xpath = "//div[#class='highcharts-axis-labels highcharts-xaxis-labels']/span[2]/div";
WebElement element=driver.findElement(By.xpath(xpath));
System.out.println("date="+element.getText());
Actions action= new Actions(driver);
action.moveToElement(element).contextClick(element).build().perform();
action
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ENTER)
.build().perform();
Kindly suggest.Also, how can I select "Show Impressions Label" based on the text and not the arrow keys?
Any help will be appreciated.
Possible Solution Only , Based on my previous observations :: You are doing it in 2 lines. Combine this and you should be able to do so. Second perform takes focus away from element. And thus the continuity is broken.
action.moveToElement(element).contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_RIGHT).sendKeys(Keys.ENTER).build().perform();

Having issue in selecting drop down element under makemytrip website

Having issue in selecting drop down element under the following website
http://flights.makemytrip.com/makemytrip/fareCal.do?intid=NewHP_to_DF_FC_Menu
I'm unable to select any one of the cities listed below.
Please help me out resolving the same.
Scenarios Tried
driver.findElement(By.className("chzn-single")).click();
driver.findElement(By.xpath("//span[contains,'NewDelhi']")).click();
driver.findElement(By.xpath("//span[#id='fromcity_chzn']")).click();
This works:
WebElement leavingFrom = driver.findElement(By.xpath("//*[#id='fromcity_chzn']/a"));
WebElement goingTo = driver.findElement(By.xpath("//*[#id='tocity_chzn']/a"));
leavingFrom.click();
leavingFrom.sendKeys("Bangalore");
leavingFrom.sendKeys(Keys.RETURN);
goingTo.click();
goingTo.sendKeys("Goa");
goingTo.sendKeys(Keys.RETURN);
Here is working sample:
//First get main dropDowns
var leavingFromDropDown = driver.FindElement(By.Css("#fromcity_chzn"));
var goingToDropDown = driver.FindElement(By.Css("#tocity_chzn"));
//Select value from first dropDown using dropDown items index
//First click on dropDown to open it
leavingFromDropDown.click();
//Now find items in it and click on any item using it's index (also can be used method to access this elements using their names
leavingFromDropDown.FindElements(By.Css(".active-result"))[1].click();
//this dropDown closes automatically, but if not you need to click on it again to close
//Same perform with second element
goingToDropDown.click();
goingToDropDown.FindElements(By.Css(".active-result"))[2].click();
If you want to use input box to enter any value from DropDown you need to find that element and using sendKeys set it's value. E.g.:
leavingFromDropDown.click();
var input = leavingFromDropDown.FindElement(By.Css(".chzn-search > input"));
input.sendKeys('Goa');
input.sendKeys(Keys.Enter);//or tab