Java xpath selenium 中的脚本错误

Java Script Error in xpath selenium

enter image description here下面是我写的脚本,初始步骤运行良好,但在我必须单击的地方开始停止工作,它会打开一个弹出框,我必须在其中发送密钥并单击关闭。

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();
    }

当执行上面的代码时,我得到了这个错误:

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.

为此:- 我想做的就是单击网页上的一个元素,在弹出窗口中输入文本,然后单击弹出窗口上的按钮关闭该弹出窗口盒子.

您需要做以下事情:-

1)弹出窗口生成后,切换到该弹出窗口

2) 现在您可以与该弹出窗口中显示的元素进行通信,例如您要发送密钥的文本字段。

3) 然后点击按钮关闭弹窗

代码是:-

1) 点击link后,弹窗打开后,写下

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

2) 向文本字段发送数据:

   alert.sendKeys("Text");

3) 关闭弹窗:

   alert.accept();

否则您可以使用:打开弹出窗口后执行此操作。

driver.switchTo().activeElement();

我希望这对你有用。