2017-07-18 52 views
0

enter image description here下面是我编写的脚本,它在初始步骤中运行良好,但它开始停止工作,必须单击它并打开一个弹出框,在该框中必须发送密钥并单击关。xpath selenium中的Java脚本错误

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.

+0

“HTML”代码在哪里? –

回答

1

对于这一点: -所有我试图做的是点击网页上的元素,输入文字,在弹出的然后单击弹出框上的按钮关闭该弹出框。

你需要做以下的事情: -

1)一旦生成弹出,切换到弹出

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

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

代码是这样的: -

1)点击链接后,并弹出打开时,写这篇文章。

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

2)将数据发送到文本字段:

alert.sendKeys("Text"); 

3)要关闭弹出:

alert.accept(); 

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

driver.switchTo().activeElement(); 

我希望这会对你有用。

+0

嗨Rohit,感谢您的回复。我尝试过,但没有工作。可能是因为它不是一个警报,但它是一个弹出式窗口,我在文本框中输入一些文本以显示添加文件夹名称,然后单击创建以创建。你有没有其他的投入。 –

+0

你能告诉我一个截图和网页代码吗?我想我可以帮你解决这个问题。 – Rohhit

+0

你也可以提到应用程序的链接,如果它对你有好处。如果你这样做会很好。我可以尝试写剧本。 – Rohhit