Selenium Webdriver: Mouse cursor hovering is not working - selenium

Selenium Webdriver: Mouse cursor hovering is not working for firefox version 50
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Ajax_Mouse_Interactions {
public static void main(String[] args) throws InterruptedException {
Path for firefox driver
System.setProperty("webdriver.gecko.driver",
"C://Users//user2//Downloads//geckodriver-v0.11.1-win64//geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.amazon.in/");
Thread.sleep(20000);
Actions class for mouse handling
Actions action = new Actions(driver);
WebElement element=driver.findElement(By.linkText("nav-link-yourAccount"));
action.moveToElement(element).build().perform();
}
}
Getting following exception
Upsupported Command Exception

I'm trying this now.
This code works for me.
import java.awt.Robot;
...
Point point = webDriver.findElement(By.xpath("//a[#title='Emitir Guias']")).getLocation();
System.out.println(point.toString());
Robot robot = new Robot();
robot.mouseMove(point.x+10,point.y+110); //This 10 and 110 just to adjust coordenate in my case
Thread.sleep(3000); //Pause for you see the mouse move
Source https://stackoverflow.com/posts/12978079/revisions

Gecodriver + Selenium 3.0.1 has issues with Actions class.
Refer following links for more details.
https://github.com/mozilla/geckodriver/issues/233
https://github.com/mozilla/geckodriver/issues/322
https://github.com/SeleniumHQ/selenium/issues/2581
So dvice is to drop back to selenium v2.53.1 and firefox browser 47.0
Thanks !

For selenium webdriverjs 3.6 javascript mouseMove can be used for mouse hover
const actions = driver.actions({ bridge: true });
driver.findElement(By.css('#mousehover'))
.then(function (elem) {
actions.mouseMove(elem).perform();
driver.sleep(1000)
// other actions..
});`

Related

ElementNotInteractableException: element not interactable in Selenium Java

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class E2E {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.flygofirst.com/");
driver.findElement(By.xpath("//span[#id='onewaymodal-id']")).click();
Thread.sleep(25000);
driver.findElement(By.xpath("//div[#id = 'oneWaybd']//div[#class ='fromTo']/div[1]")).sendKeys("Ch");
}
}
I Tried to SendKeys in the From Text Box i was getting Element not Intractable.
And I provided Waiting time so that all the web elements will load. After that also i got the same exception Element not Intractable.
Can anyone help me with this
You have to modify the locator, try this one, its working:
// to handle the Accept Cookies button
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#cookie-btn"))).click();
driver.findElement(By.xpath("//span[#id='onewaymodal-id']")).click();
Thread.sleep(1000);
// modified the below locator
driver.findElement(By.xpath("(.//div[#class='fromTo']//input[#id='roundTripbdFromView'])[2]")).sendKeys("ch");
I answered your previous question also, check that, if it works, mark that as the answer.

I need to read the text with the tooltip, I've tried a lot of ways and I always get the result that I can't find that element (selenium-java)

I need to read the text with the tooltip, I've tried a lot of ways and I always get the result that I can't find that element (selenium-java)
https://demoqa.com/tool-tips
To inspect tooltip's html code you need to freeze the dom -> Freeze screen in chrome debugger / DevTools panel for popover inspection?
Code:
package selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
public class TooltipTest extends WebDriverSetup {
public static void main(String[] args) {
WebDriver driver = startChromeDriver(); // wrapped driver init
driver.get("https://demoqa.com/tool-tips");
WebElement toolTipButton = driver.findElement(By.id("toolTipButton"));
Actions action = new Actions(driver);
action.moveToElement(toolTipButton).perform();
WebElement tooltip = driver.findElement(By.className("tooltip-inner"));
System.out.println(tooltip.isDisplayed());
System.out.println(tooltip.getText());
driver.quit();
}
}
Output:
Starting ChromeDriver 92.0.4515.43 (8c61b7e2989f2990d42f859cac71319137787cce-refs/branch-heads/4515#{#306}) on port 25112
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Zář 03, 2021 8:52:54 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
true
You hovered over the Button

NoSuchElementException while executing my testscript

Observing following error while executing my test script. Can someone help me in identifying the cause of failure.
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"lid"}
Command duration or timeout: 20.45 seconds
Here is the snippet of my code. Please note that the element exist in same frame hence frame switch is not needed.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.ExpectedConditions;
//import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class LoginPage
{
#Test
public void testLoginFail()
{
WebDriver driver = new FirefoxDriver();
driver.get("https://www.zoho.com/crm/");
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.linkText("LOGIN")).click();
//WebDriverWait wait = new WebDriverWait(driver,40);
//wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("lid"))));
driver.findElement(By.id("lid")).sendKeys("xyz#gmail.com");
HTML view of the element is:
<input name="lid" id="lid" class="input usrbx" value="" onkeypress="clearmsg()" type="email">
I have inspected the webpage "https://www.zoho.com/crm/lp/login.html" and i am able to see an iframe in it and the input text boxes are inside it. Below is the working code.
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\Selenium\\Web Drivers\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.zoho.com/crm/");
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.linkText("LOGIN")).click();
//Switch to the frame
driver.switchTo().frame(0);
driver.findElement(By.id("lid")).sendKeys("xyz#gmail.com");
driver.quit();
}
Hope this helps you. Thanks.
Here is the Answer to your Question:
A few words about the Solution:
While working with Selenium 3.4.0 with geckodriver v0.16.1 & Mozilla Firefox 53.0 you need to download the latest geckodriver from here and provide the absolute path of the geckodriver through System.setProperty.
Try to avoid implicitlyWait as per recent updates implicitlyWait may die in fire soon.
The error you are seeing NoSuchElementException says it all. The id of the element is not traceable.
The element with id lid is within an iframe, so you need to switch to frame first.
Here is your own code with some simple tweaks in it:
#Test
public void testLoginFail()
{
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.zoho.com/crm/");
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.linkText("LOGIN")).click();
driver.switchTo().frame("zohoiam");
driver.findElement(By.xpath("//input[#id='lid']")).sendKeys("xyz#gmail.com");
}
Let me know if this Answers your Question.

Not able to click the Inline element using selenium webdriver

enter image description hereNot able to click the inline element using selenium webdriver.
Here is the URL
https://www.google.com/.
Besides Images link (Right side top) there is a square icon. Need to click that icon and select Maps.
Screenshot attached.
I used xpath, cssselector, ID, Name but nothing is working.
Could anyone help me on this.
Code:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class webelements2 {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver","C:\\Users\\rpremala003\\Downloads\\geckodriver-v0.14.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.findElement(By.id("gbwa")).click();
driver.findElement(By.className("gb_3")).click();
}
}
This code is somehow not working in Firefox because it opens the Products page when you click on element - By.id("gbwa"). But if you try the same in Chrome, it works fine. Only thing you would need to change is By.className("gb_3") with By.xpath("//ul[#class='gb_ka gb_da']/li[3]").
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.findElement(By.id("gbwa")).click();
driver.findElement(By.xpath("//ul[#class='gb_ka gb_da']/li[3]")).click();
For Firefox, you can modify the code so that when the products page is opened, you can click on the Maps option from there.
Some dynamic waits need to be added for controls. Additionally, I noticed that, if google is not set as your home page then you see a message 'Come here often? Make Google your homepage.'. This message needs to be handled, otherwise it will fail the access to the apps icon.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class webelements2 {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver","C:\\Users\\rpremala003\\Downloads\\geckodriver-v0.14.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
driver.manage().window().maximize();
WebDriverWait wait = new WebDriverWait(driver, 10);
if (driver.findElements(By.xpath("//a[#title='No thanks']")).size() !=0) {
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//a[#title='No thanks']"))));
driver.findElement(By.xpath("//a[#title='No thanks']")).click();
}
driver.findElement(By.xpath("//div[#id='gb']//div[#id='gbwa']/div/a[#title='Google apps' and #role='button']")).click();
wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//a[#id='gb8']/span[text()='Maps']"))));
driver.findElement(By.xpath("//a[#id='gb8']/span[text()='Maps']")).click();
}
}
Try this code and let me know, if you have further queries.
I've tested the code below and it works.
driver.get("https://www.google.com");
driver.findElement(By.cssSelector("a[title='Google apps']")).click();
new WebDriverWait(driver, 3).until(ExpectedConditions.elementToBeClickable(By.id("gb8"))).click();
You basically need to click the Apps icon, wait for the Maps icon to be clickable, and click it.
I'm assuming you don't work for Google so in that case, why test the UI? You can just directly navigate to https://maps.google.com and skip the UI clicks.
How about this ... worked for me.
driver.get("https://www.google.com/");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[#id='gbwa']//a[#title='Google apps']"))));
driver.findElement(By.xpath(".//*[#id='gbwa']//a[#title='Google apps']")).click();
//click map icon
driver.findElement(By.cssselector("a#gb8")).click();
Use this, working for me.
Use Chrome driver instead of Firefox driver.
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class GoogleMaps {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.google.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[#id='gbwa']")).click();
driver.findElement(By.xpath("//li/a[#id='gb8']")).click();
Thread.sleep(6000);
driver.quit();
}
}
Output :

Element is not clickable at point using chrome driver

I am trying to download payslip as PDF from greytip web portal using chrome driver.i am trying to click on link salary by using "driver.findElement(By.linkText("Salary")).click();".But i am unable to click the link and failed with following exception.
Error
org.openqa.selenium.WebDriverException: Element is not clickable at point (198, 139). Other element would receive the click: ... (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 37 milliseconds
And also when ever i ran the script chrome open one extra tab for bit torrent.so here when i ran the program one tab is opened for "https://psdpl.greytip.in" and another tab is opened for bittorrent.How can i handle not to open another bittorrent tab when i ran the program.
Here i am attaching the code and screen shots.enter image description here
Code
package com.webdriver.tests;
import static org.junit.Assert.*;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class PaySlipPDF {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\soleti\\D-Drive\\Selenium\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "https://psdpl.greytip.in/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
#Test
public void testPayslip() throws Exception {
driver.get(baseUrl + "/login.do");
driver.findElement(By.id("j_username")).clear();
driver.findElement(By.id("j_username")).sendKeys("101786");
driver.findElement(By.id("j_password")).clear();
driver.findElement(By.id("j_password")).sendKeys("password");
driver.findElement(By.id("login-button")).click();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
//driver.findElement(By.xpath("//*[#id='home-page']/div[1]/div[1]/ul/li[2]/a")).click();
WebElement elementToClick = driver.findElement(By.xpath("//*[#id='home-page']/div[1]/div[1]/ul/li[2]/a"));
System.out.println(elementToClick);
// Scroll the browser to the element's Y position
((JavascriptExecutor) driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().y+")");
// Click the element
elementToClick.click();
//driver.findElement(By.linkText("Salary")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.linkText("View Payslips")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
new Select(driver.findElement(By.id("payroll"))).selectByVisibleText("Mar 2012");
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.findElement(By.className("btn btn-gts-print")).click();
}
#After
public void tearDown() throws Exception {
//driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}
It is the BitTorrent toolbar that is causing the issue. It is launched into Chrome by an extension. Either uninstall it completely, or force Selenium to tell Chrome to disable all extensions. This can be done using the ChromeOptions class:
http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/chrome/ChromeOptions.html
Use the addArgument method and give it this arguement, which tells Chrome to disable all user extensions:
--disable-extensions
Check the browser settings and see if the default homepage has been changed by the bit torrent toolbar that is installed. If not needed, try to uninstall the bitTorrent toolbar from the browser and rerun your selenium program. Hope this helps.
This problem is specificaly related to chrome installed on your system..Uninstall the google chrome and re-install it..That will fix your problem..:)