0

My Code is as below, I'm executing the script using the Mac and running 2 nodes, 1 on windows and 1 on the mac itself. The upload on the Mac works perfect but the windows upload doesnt work.

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();    
StringSelection str = new StringSelection("C:\\Sheyan.pdf");   
clipboard.setContents(str, str);
if (systemType=="http://192.168.1.100:5555/wd/hub")    **(THIS IS THE WINDOWSOS NODE)**     
{       
    Robot robot = new Robot();      
    robot.keyPress(KeyEvent.VK_CONTROL);        
    robot.keyPress(KeyEvent.VK_V);        
    robot.keyRelease(KeyEvent.VK_V);        
    robot.keyRelease(KeyEvent.VK_CONTROL);        
    robot.keyPress(KeyEvent.VK_ENTER);        
    robot.keyRelease(KeyEvent.VK_ENTER);        
}   
else **(FOR MAC OS NODE)**
{       
    selenium.click(driver, UploadButton);       
    WebElement fileInput = driver.findElement(UploadButton);        
    fileInput.sendKeys("/Users/accesstesting/Documents/Sheyan.pdf");        
}
4

2 回答 2

2

这永远不会起作用,机器人命令在运行脚本的机器上运行,它们不会传递给节点。仅当测试在本地机器上运行时,使用您正在使用的机器人实现才会起作用。

如果您正在针对远程节点运行测试,您想要做的是使用本地文件检测器:

driver.setFileDetector(new LocalFileDetector())

然后,您只需使用普通的 sendKeys() 方法使用本地文件填充上传输入,Selenium 将在后台执行一些魔术以将任何文件传递通过网格,以便它们可以正确上传。

于 2013-04-05T10:30:21.497 回答
0

我知道这更像是一个问题而不是一个答案,但仍然:你为什么在 Windows 节点上使用 Robot 而在 Mac 节点上使用 Selenium?

如果你这样做会发生什么?

 if (systemType=="http://192.168.1.100:5555/wd/hub")    **(THIS IS THE WINDOWSOS NODE)** 
 {       
  selenium.click(driver, UploadButton);       
  WebElement fileInput = driver.findElement(UploadButton);        
  fileInput.sendKeys("C:\\Sheyan.pdf");        
}

因为如果在 Windows 节点上正确初始化 selenium 和驱动程序,这应该可以工作

于 2013-04-03T08:55:21.197 回答