Avinash Pandey
Avinash Pandey

Reputation: 61

Java Script Error in xpath selenium

enter image description hereBelow is the script that I wrote, and it goes well with initial steps but it starts to stop working where I have to click and it opens a popup box where i have to send keys and click close.

package pages;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;

import appSetup_Maven.test.BaseClass;

public class UploadFile extends BaseClass {

    @Test
    public void logout() throws IOException {
        Login();
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    }

        @Test
        public void uploadFile() throws Exception {

            driver.findElement(By.xpath(".//*[@id='sidebar-menu']/ul/li[5]/a/span[1]")).click();
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver.findElement(By.xpath(".//*[@id='sidebar-menu']/ul/li[5]/ul/li[4]/a/span")).click();
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

            driver.findElement(By.xpath(".//*[@id='drives-gridview']/table/tbody/tr[1]/td[1]/a")).click();
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver.findElement(By.xpath(".//*[@id='wrapper']/div[3]/div/div[2]/div[2]/div/div[2]/div/a[1]")).click();
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver.findElement(By.xpath(".//*[@id='explorer-content']/div[2]/div/div/div/div[2]/div/div[1]/div/div[1]/button[2]")).click();
            driver.findElement(By.xpath(".//*[@id='folderName']")).sendKeys("Test");
            driver.findElement(By.xpath(".//*[@id='folderName']")).sendKeys("Test");
            driver.findElement(By.xpath(".//*[@id='createFolderForm']/div[3]/button[2]")).click();
    }

When execute above code, I got this Error:

JavaScript warning: www.wwwww.com/assets/js/clipboard.min.js, line 1: mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create ************************************************************ * Call to xpconnect wrapped JSObject produced this error: * [Exception... "[object Object]'[object Object]' when calling method: [nsIConsoleListener::observe]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "native frame :: :: :: line 0" data: no] ************************************************************ ************************************************************ * Call to xpconnect wrapped JSObject produced this error: * [Exception... "[object Object]'[object Object]' when calling method: [nsIConsoleListener::observe]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "native frame :: :: :: line 0" data: no] ************************************************************ JavaScript warning: , line 0: https://hq20m-161112.wwww.com:10036/js/iframeResizer.contentWindow.min.js is being assigned a //# sourceMappingURL, but already has one ************************************************************ * Call to xpconnect wrapped JSObject produced this error: * [Exception... "[object Object]'[object Object]' when calling method: [nsIConsoleListener::observe]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "native frame :: :: :: line 0" data: no] ************************************************************

Not sure why i am getting this error. All i am trying to do is to click an element on the webpage, enter text in the popup and click the button on the popup to close that popup box.

Upvotes: 0

Views: 130

Answers (1)

Rohhit
Rohhit

Reputation: 742

For this: - All i am trying to do is to click an element on the webpage, enter text in the popup and click the button on the popup to close that popup box.

You need to do following things :-

1) Once the pop-up is generated, switch to that pop-up

2) Now you can communicate with the elements present on that pop-up like text field where you are going to send keys.

3) Then click on button to close the pop-up

Code for this is :-

1) After clicking on link, and when pop-up opens, write this.

 Alert alert=driver.switchTo().alert();

2) To send data to the text field :

   alert.sendKeys("Text");

3) To close the pop-up :

   alert.accept();

Or else you can use : after opening the pop-up do this.

driver.switchTo().activeElement();

I hope this will work for you.

Upvotes: 1

Related Questions