Unable to right click and select a value using Selenium Webdriver - selenium

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();

Related

How can I automate clicking and choosing from dropdown menu and saving?

There is a database of students about 200, I need to choose 2 items from dropdown and click on save button at the end.
Doing manually takes about 5-6 sec. I want to know if it's possible to automate it?
Screenshots below:
Then choosing 2 items:
Finally hit "save"button:
In selenium you could do it like this:
WebElement mySelectElement = driver.findElement(By.id("id of the dropdown"));
Select dropdown= new Select(mySelectElement);
dropdown.selectByIndex(2);//select it by index
driver.findElement(By.id("id of your button")).click();

Unable to Click on Edit Button , in WebTable

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')]

How to select absolute link if two links are having same text in them?

I am having two link
Engagement Rings
Rings
The above links are check box under dropdown menu
how can i select Rings using selenium xpath using text() method
Below is what i tried, but it is selecting "Engagement Ring"
//li//a[contains(text(),'Rings')]
but it is selecting Engament Ring as it appears before Rings in menu
My Code:
//Select Sub-Menu item from collection dropdown
WebElement selectSub = driver.findElement(By.xpath("//div[#class='popover fade right in']//div[2]//li//a[contains(text(),'Rings')]"));
This is selecting Engagement Rings because you are using contains() method
it will locate the element which contains match text So your first checkbox has "Rings" text
Just change your xpath to :
//li//a[text()='Rings']
OR
//li//a[normalize-space()='Rings']
Please try below xpath i hope it will work
//li//a[starts-with(text(),'Rings')]

How to select value from Google auto location using Selenium

How to automate this to select particular value even the dropdown list id cannot be inspected. Can anyone help me out on this?
Need to select U.S. 22 Imperial from the list
Please find the HTML snippet
I am unable to proceed more than this. Please help me out!
WebElement location = driver.findElement(By.id("selectbox-city-list2"));
location.sendKeys("us");
You could use sendKeys and send arrow down to select an option. Selecting one by one with the arrow down will highlight the value. You will be able to check the highlighted value using the CSS class of highlighting.
You can use ActionClass
using this you can move your cursor over a specific element based on coordinates and perform a click.
1.So taking the coordinates of that text box.
2.Enter the full value in the text box. ,
3.calculate a very near coordinate to that text box(so that it will be the suggestion) and perform a click.
element = xxxxxxx;
Actions builder = new Actions(driver);
builder.moveToElement(element, x_coord, y_coord).click().build.perform();

How to traverse all the element of dropdown in Selenium WebDriver?

I have a drop down on my web page and I have to traverse this drop down and select the specific one.But its not so simple, In this the traversing should be show by the hover and at last the specific element or item should be selected.(The mouse hover action should start from the first element till the required element and then select the element).
You need to look into Select, there are a couple of different ways of selecting elements from the dropdown, below is one example.
Select dropdown = new Select(<WebElement>);
dropdown.selectByVisibleText("text");