Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Java-如何从Firefox设置桌面背景?_Java_Selenium - Fatal编程技术网

Selenium Java-如何从Firefox设置桌面背景?

Selenium Java-如何从Firefox设置桌面背景?,java,selenium,Java,Selenium,这是我的第一个问题 我是Selenium的新手,我正在尝试一个简单的自动化示例。正如标题所说,我想做的是: -打开Firefox>转到图像链接>右键单击图像>转到“设置为背景”选项(单击它)>最后单击出现的弹出窗口上的“设置背景” 最后一步是我的问题,我已经完成了所有步骤,但是当确认弹出窗口或紧急窗口(我不知道它是什么)出现时,我无法单击按钮或发送回车键 这是我的密码: public class firstSteps { public static void main(String[] arg

这是我的第一个问题

我是Selenium的新手,我正在尝试一个简单的自动化示例。正如标题所说,我想做的是:

-打开Firefox>转到图像链接>右键单击图像>转到“设置为背景”选项(单击它)>最后单击出现的弹出窗口上的“设置背景”

最后一步是我的问题,我已经完成了所有步骤,但是当确认弹出窗口或紧急窗口(我不知道它是什么)出现时,我无法单击按钮或发送回车键

这是我的密码:

public class firstSteps {

public static void main(String[] args) {
    // TODO Auto-generated method stub
//  System.setProperty("webdriver.firefox.driver", "C:\\Mozilla Firefox\\firefox.exe");
    File pathBinary = new File("C:\\Mozilla Firefox\\firefox.exe");
    FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
    FirefoxProfile firefoxProfile = new FirefoxProfile();       
    WebDriver driver = new FirefoxDriver(firefoxBinary, firefoxProfile);
    driver.get("http://www.planwallpaper.com/static/images/Wallpapers-for-Background-HD-Wallpaper-1080x607.jpg");
    //Right click 
    Actions rClick = new Actions(driver);
    String title = driver.getTitle();
    System.out.println(title);
    rClick.contextClick(driver.findElement(By.xpath("//html//body//img"))).build().perform();
    //Move through menu
    rClick.sendKeys(Keys.ARROW_DOWN).build().perform();
    rClick.sendKeys(Keys.ARROW_DOWN).build().perform();
    rClick.sendKeys(Keys.ARROW_DOWN).build().perform();
    rClick.sendKeys(Keys.ARROW_DOWN).build().perform();
    rClick.sendKeys(Keys.ARROW_DOWN).build().perform();
    //Select option
    rClick.sendKeys(Keys.ENTER).build().perform();
    //Here I should click on that option
}
}

我试着在新标签页中移动,发送回车键,也只发送回车键,因为这两个键在手动操作时都可以工作,但都不起作用


提前谢谢

运行代码时会发生什么?你能调试和分享正在发生的事情吗?当我运行这段代码时,很难根据“none has worked”来建议更改。它只是打开浏览器,转到图像链接,右键单击它,然后选择“Set as background”(设置为背景)选项。之后会出现一个窗口,我不知道如何管理它,因为我不知道它是窗口还是弹出窗口。