2

TestCase class is where I initailize the driver and invoke the url (url "http://www.amazon.in/")

public class TestCase { 
    InitializeDriver id = new InitializeDriver();
    WebDriver driver = null;

    @BeforeTest
    public void setup()
    {
        id.invokeApplicationUrl();
        driver = id.getDriver();

    }

}

TC1 is my test to go to Amazon sign in page

public class TC1 extends TestCase {
    @Test
    public void runTC1 () 
    {
        GoToSignInPage gts = new GoToSignInPage(driver);
        gts.clickElement();
    }
}

Logic to go to the sign in page is written in GoToSignPage is written

public class GoToSignInPage {

    WebDriver driver;

    public GoToSignInPage(WebDriver driver)
    {
        this.driver=driver;
    }

    InitialPage ip = new InitialPage(driver);
    InitializeDriver id = new InitializeDriver();

    public void clickElement()
    {
        Actions action = new Actions(driver);
        //driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        //ip.yourOrders(driver).click();
        jse.executeScript("argument[0].style.border='3px dotted blue'", ip.yourOrders(driver));
action.moveToElement(ip.yourOrders(driver)).moveToElement(ip.signInBt(driver)).click().build().perform();
}

InitialPage class has all the required page objects

public class InitialPage {

    WebDriver driver;

    public InitialPage(WebDriver driver)
    {
        this.driver = driver;
    }

    WebElement element ;

    public WebElement yourOrders(WebDriver driver)
    {
        element = driver.findElement(By.id("nav-link-yourAccount"));
        return(element);

    }
    public WebElement signInBt(WebDriver driver)
    {
        element = driver.findElement(By.xpath(".//*[@id='nav-flyout-ya-signin']/a/span"));
        return(element);

    }

}

Error is as below

org.openqa.selenium.WebDriverException: unknown error: argument is not defined (Session info: chrome=56.0.2924.87) (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 6.3.9600 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 22 milliseconds Build info: version: '3.0.0-beta1', revision: '8e4315c', time: '2016-07-28 18:04:05 -0700' System info: host: 'VAIO', ip: '192.168.0.6', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf), userDataDir=C:\Users\Akash\AppData\Local\Temp\scoped_dir6352_11834}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=56.0.2924.87, platform=WIN8_1, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: f74e69d9f66bab833287a8fd6f9d3021 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

2 Answers 2

3

One simple solution is to change jse.executeScript("argument[0].style.border='3px dotted blue'", to jse.executeScript("arguments[0].style.border='3px dotted blue'",

Sign up to request clarification or add additional context in comments.

Comments

2

Your error comes from executing this JavaScript code jse.executeScript("argument[0].style.border='3px dotted blue'", try loading the website in your browser (i.e. Chrome), open developer tools (F12), navigate to console, input the same command, and you will get the same error:

enter image description here

According to Selenium documentation,

The arguments will be made available to the JavaScript via the "arguments" variable.

In your code, you use argument[0] instead of arguments[0]

4 Comments

But I am passing the argument, the complete command is as below
based on your comment, it looks like you want to execute the following JavaScript, document.getElementById('nav-link-yourAccount').style.border='3px dotted blue'. BTW, this will result in another exception if there is no element with given ID, so, I would add a check condition for that
another option to try, is to change to arguments[0] Note: s at the end of the variable, it is missing in your code
@AkashChavan : go as per oldbam's latest comment; this is the probable cause to your problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.