serenity-bdd / serenity-core

Serenity BDD is a test automation library designed to make writing automated acceptance tests easier, and more fun.
http://serenity-bdd.info
Other
719 stars 516 forks source link

org.openqa.selenium.UnsupportedCommandException: sendKeysToActiveElement #2099

Closed gopal3008 closed 2 years ago

gopal3008 commented 4 years ago

The class in which I want to perform some actions extends to PageObject. Please help how to fix this issue.

Below is the code: Actions actions = new Actions(getDriver); WebElement emptyElement = getDriver().findElement(By.xpath("//*[text()='Crear una cuenta']")); actions.contextClick(emptyElement).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform(); Actions action = new Actions(getDriver()); action.contextClick(emptyElement).build().perform(); action.contextClick(emptyElement).build().perform(); Robot robot = new Robot(); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_ENTER);

And Below is the Error: org.openqa.selenium.UnsupportedCommandException: sendKeysToActiveElement Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'USABOS133029L', ip: '10.129.147.28', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.1' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:218) at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:117) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:152) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35) at org.openqa.selenium.remote.RemoteKeyboard.sendKeys(RemoteKeyboard.java:38) at org.openqa.selenium.interactions.SendKeysAction.perform(SendKeysAction.java:56) at org.openqa.selenium.interactions.CompositeAction.perform(CompositeAction.java:34) at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:642) at com.adidas.membership.program.unit.member.gherkindefinitions.UtilityRewardsProgram.translateToEnglish(UtilityRewardsProgram.java:28) at com.adidas.membership.program.unit.member.gherkindefinitions.CoLoginPageDetails.openCOUrl(CoLoginPageDetails.java:34) at com.adidas.membership.program.unit.member.gherkindefinitions.CoLoginPage.openApplication(CoLoginPage.java:14) at com.adidas.membership.program.unit.member.gherkindefinitions.CoLoginPage$$EnhancerByCGLIB$$cb8219a1.CGLIB$openApplication$0() at com.adidas.membership.program.unit.member.gherkindefinitions.CoLoginPage$$EnhancerByCGLIB$$cb8219a1$$FastClassByCGLIB$$1638fce0.invoke() at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at net.thucydides.core.steps.StepInterceptor.invokeMethod(StepInterceptor.java:464) at net.thucydides.core.steps.StepInterceptor.executeTestStepMethod(StepInterceptor.java:449) at net.thucydides.core.steps.StepInterceptor.runTestStep(StepInterceptor.java:424) at net.thucydides.core.steps.StepInterceptor.runOrSkipMethod(StepInterceptor.java:165) at net.thucydides.core.steps.StepInterceptor.testStepResult(StepInterceptor.java:152) at net.thucydides.core.steps.StepInterceptor.intercept(StepInterceptor.java:70) at com.adidas.membership.program.unit.member.gherkindefinitions.CoLoginPage$$EnhancerByCGLIB$$cb8219a1.openApplication()

wakaleo commented 4 years ago

UnsupportedCommandException sounds like a driver issue - the method Selenium is using is not supported by the driver.

gopal3008 commented 4 years ago

I made sure that my driver and browser version are in sync what else I could try to do.

Also I use the below code in a completely new project to check if the issue persists but there it is working perfectly fine not sure why not with serenity

System.setProperty("webdriver.chrome.driver", "src/test/resources/webdriver/windows/chromedriver.exe");

       WebDriver driver = new ChromeDriver();
       driver.manage().window().maximize();
       driver.get("https://www.lambdatest.com/feature");
       Actions actions = new Actions(driver);
       WebElement elementLocator = driver.findElement(By.xpath("//*[@id=\"vid\"]"));
      actions.contextClick(elementLocator).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();
       Actions action = new Actions(driver);
       action.contextClick(elementLocator).build().perform();
       Robot robot = new Robot();
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_ENTER);
wakaleo commented 4 years ago

What version of Serenity are you using?

gopal3008 commented 4 years ago

I am using 2.0.24

wakaleo commented 4 years ago

Can you provide a sample project showing how it works with plain Selenium action classes and not when you run it through Serenity?

gopal3008 commented 4 years ago

Ok This is the new Project with one single class only and it works fine Here: public static void main(String[] args) throws AWTException, InterruptedException { // TODO Auto-generated method stub

    System.setProperty("webdriver.chrome.driver", "src/test/resources/webdriver/windows/chromedriver.exe");

       WebDriver driver = new ChromeDriver();
       driver.manage().window().maximize();
       driver.get("https://www.lambdatest.com/feature");
       Actions actions = new Actions(driver);
       WebElement elementLocator = driver.findElement(By.xpath("//*[@id=\"vid\"]"));
      actions.contextClick(elementLocator).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();
       Actions action = new Actions(driver);
       action.contextClick(elementLocator).build().perform();
       Robot robot = new Robot();
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_DOWN);
       Thread.sleep(2000);
       robot.keyPress(KeyEvent.VK_ENTER);
   }

And in my project I am using below method:

public class ABC extends PageObject {

public void translateToEnglish() throws InterruptedException, AWTException {

    Actions actions = new Actions(getDriver());
    WebElement emptyElement = getDriver().findElement(By.xpath("//*[text()='XYZ']"));
    actions.contextClick(emptyElement).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();

// Actions action = new Actions(getDriver()); actions.contextClick(emptyElement).build().perform(); // action.contextClick(emptyElement).build().perform(); Robot robot = new Robot(); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_DOWN); Thread.sleep(2000); robot.keyPress(KeyEvent.VK_ENTER); }} Let me know if you need more details

wakaleo commented 4 years ago

I mean a project that I can clone or download and run locally to reproduce the issue.

gopal3008 commented 4 years ago

It would be difficult to do so because I work in client environment and can't do the same.

My code is working till WebElement emptyElement = getDriver().findElement(By.xpath("//*[text()='XYZ']"));

It gives the error in very next line. If nothing can't be done I will try to create a sample project but it would consume lot of time. What do you suggest ?

wakaleo commented 4 years ago

First, try with 2.2.8. Then create a new project from one of the starter projects and add the code that fails, so that I can reproduce it outside of your environment. The problem can't be fixed if it can't be reproduced.

gopal3008 commented 4 years ago

I will try to create a demo project for you to have it.

gopal3008 commented 4 years ago

So I tried to create the dummy project but surprisingly the code worked over there but it is still not working in my existing framework or Project. I am so gutted right now. Still giving the same

Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'USABOS133029L', ip: '10.110.112.121', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.1' Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.remote.http.AbstractHttpCommandCodec.encode(AbstractHttpCommandCodec.java:218)

wakaleo commented 4 years ago

Using the Robot class is pretty unreliable in my experience (depends on a lot of factors outside of your control). Have you considered using Javascript to perform the action you are trying to achieve, or bypassing this step in some way?

gopal3008 commented 4 years ago

Actually I am trying to create a framework for non English countries. So it is possible to leave this step but the rework will increase when I would change from one non English country to another non English country. So overall efficiency will go down. I can still share the project if you could help where I want to change the language of the webpage.

globalworming commented 4 years ago

I am confused.. How is language related to this?

gopal3008 commented 4 years ago

Ok so my final objective is to change the language of the webpage which I am trying to do using the actions and Robot class where I right click on page and then click on translate to English option. Now it is working when I am doing separately in a standalone serenity project but some how is not working in my existing framework or project.

globalworming commented 4 years ago

then spot the difference :) there must be one

gopal3008 commented 4 years ago

Yeah I am trying my best. The issue is that the existing framework is huge with 100s of class. But the one which is working is having only one class so it difficult for me I am trying to find one. Thats why thought is there any other way.