power_settings_new

java.lang.IllegalArgumentException

by (391 points)
+1 vote
1.1k views
Argument is of an illegal type: org.openqa.selenium.By$ByXPath
    at org.openqa.selenium.remote.internal.WebElementToJsonConverter.apply(WebElementToJsonConverter.java:80)
    at com.google.common.collect.Iterators$8.transform(Iterators.java:817)
    at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
    at com.google.common.collect.Iterators.addAll(Iterators.java:365)
    at com.google.common.collect.Lists.newArrayList(Lists.java:162)
    at com.google.common.collect.Lists.newArrayList(Lists.java:146)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:572)
    at tips.fruit.evergreen.LoginPage.clickSignInMenu(LoginPage.java:41)
    at fruit.evergreen.testcases.VerifyEvergreenLogin.verifyValidLogin(VerifyEvergreenLogin.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
by (171 points)
Can you reply to comment here by posting clickSignInMenu?
by (391 points)
Here goes the classes:
------------------------------
LoginPage.java
package tips.fruit.evergreen;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

/*
 *
 *   This class will store all the locators and methods of login page.
 *  
 */

public class LoginPage {
       
        WebDriver driver;
        By closeModalButton = By.xpath("//*[@id='planModal-home-2']/div/button");
        By signInMenu = By.xpath("//*[@id='navbar']/div[2]/div/div/div[2]/div[2]/div[2]/div[1]/span[1]");
        By menuButton = By.xpath("//*[@id='navbar']/div[2]/div/div/div[1]/button");
        //By signInMenu = By.xpath("//*[@id='navbar']/div[2]/div/div/div[1]/button");
        //By signInMenu = By.linkText("???? ?????????");
        //By signInMenu = By.partialLinkText("?????");
        By signInMenuButton = By.xpath("//*[@id='custom-registration-home-registration-form']/div/a");
        By username = By.xpath("//*[@id='edit-name']");
        By password = By.xpath(".//*[@id='edit-pass']");
        By SignInFormButton = By.xpath("//*[@id='edit-submit']");
       

        public LoginPage(WebDriver driver)
        {
            this.driver = driver;
        }
       
        public void clickCloseModalButton()
        {

            driver.findElement(closeModalButton).click();
        }
       
        public void clickMenuButton()
        {
            WebDriverWait wait = new WebDriverWait(driver, 45);
            wait.until(ExpectedConditions.visibilityOfElementLocated(menuButton));
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", menuButton);
            //driver.findElement(menuButton).click();
        }
       
        public void clickSignInMenu()
        {   
            /*
            WebDriverWait wait = new WebDriverWait(driver, 45);
            wait.until(ExpectedConditions.visibilityOfElementLocated(signInMenu));
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", signInMenu);
            */
            driver.findElement(signInMenu).click();
           
        }
       
        public void clickSignInMenuButton()
        {    /*
            WebDriverWait wait = new WebDriverWait(driver, 15);
            wait.until(ExpectedConditions.visibilityOfElementLocated(signInMenuButton));
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", signInMenuButton);*/
            driver.findElement(signInMenuButton).click();
           
        }
       
        public void typeUserName()
        {    /*
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", username);
            driver.findElement(username).sendKeys("01729111333");*/
            driver.findElement(username).click();
        }
       
        public void typePassword()
        {   
            /*
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", password);
            driver.findElement(password).sendKeys("01729111333");*/
            driver.findElement(password).click();
        }
       
        public void clickSignInFormButton()
        {   
            /*
            JavascriptExecutor exe = (JavascriptExecutor)driver;
            exe.executeScript("arguments[0].click();", SignInFormButton);
            driver.findElement(SignInFormButton).click();*/
            driver.findElement(SignInFormButton).click();
        }
       
}
----------------------------------------------------
-----------------------------------------------------
VerifyEvergreenLogin.java
package fruit.evergreen.testcases;

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;

import tips.fruit.evergreen.LoginPage;


/*
 *
 *   This class is a test case of the login page.
 *  
 */
public class VerifyEvergreenLogin {

    @Test
    public void verifyValidLogin()
    {
        WebDriver driver = new FirefoxDriver();
        //driver.manage().window().maximize();
        driver.get("http://evergreen.fruit.tips");
        //driver.get("http://mytonic.com");
       
        LoginPage logon = new LoginPage(driver);
       
        logon.clickCloseModalButton();
       
        logon.clickMenuButton();
       
        logon.clickSignInMenu();
       
        logon.clickSignInMenuButton();
       
        logon.typeUserName();
       
        logon.typePassword();
       
        logon.clickSignInFormButton();
       
        driver.quit();
    }

}
-----------------------------------------------------------

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes

You can't pass By as an argument to JavaScript. You have to convert that to WebElement.

Try below in your tips.fruit.evergreen.LoginPage.clickSignInMenu function.

JavascriptExecutor exe = (JavascriptExecutor)driver;
WebElement ele = driver.findElement(signInMenu);
exe.executeScript("arguments[0].click();", ele );
by (391 points)
After applying your solution the Illegal Argument Exception has been resolved.

Now, I am getting this error:
Element is not clickable at point (124, 23):
Other element would receive the click: <div aria-hidden="true" style="display: block;" class="modal fade" id="planModal-home-2" tabindex="-1" role="dialog" aria-labelledby="joinTonicModal"></div>
by (171 points)
Have you removed or commented? driver.findElement(signInMenuButton).click();
by (171 points)
In ExpectedConditions, try using elementToBeClickable instead of visibilityOfElement.
If the menu is a dropdown, sometimes it takes time for the element to be clickable, but it will be visible.
add
...