元素不在焦点上,无法单击

时间:2018-02-16 13:22:35

标签: java selenium selenium-webdriver

我正在尝试从输入字段中删除值并保存更改。单击“保存”按钮时出现问题。这是适用于所有其他测试的东西,只是在这里不起作用。可能是因为表单很长,我需要滚动直到元素可见。我在这里搜索并尝试了大部分建议,但没有任何效果。那是我的代码:

//deleting input field
    WebElement sesstimeout = driver.findElement(By.xpath(xpath));
    sesstimeout.clear();
    Thread.sleep(2000);
//scroll until element is viewable and click save
    WebElement savebutton= driver.findElement(By.xpath("//*[@id='orgSettingsContainer']/div/div/form/div[9]/button"));

    ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", savebutton);

    savebutton.click();
    Thread.sleep(2000);

我想清楚那个字段: enter image description here

并使用此按钮保存更改,如果不向下滚动则无法显示: enter image description here

2 个答案:

答案 0 :(得分:0)

试试这个:

使用Action类:

Actions a=new Actions(driver);
action.dragAndDropBy("scroll bar path", int xOffset, int yOffset).click();

答案 1 :(得分:0)

尝试使用此代码向下滚动:

JavascriptExecutor js = (JavascriptExecutor)driver;
                                js.executeScript("scroll(0, 1000);");
相关问题