java - 元素未获得焦点且无法单击

标签 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

最佳答案

试试这个:

使用操作类:

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

关于java - 元素未获得焦点且无法单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48827764/

相关文章:

java - 使用 Spring 定型的优点?

java - 以 -able 结尾的接口(interface)中的方法命名约定

java 运行时异常 :java. lang.nullPointerException

python - CSS 选择器在 Selenium 脚本中抛出超时异常

selenium - 等待处理程序注册 - selenium

java - 如何使用 Java 在 Selenium webdriver 中处理促销广告或 cookie

java - 在 Java 中分解数字 - 家庭作业

python - 如何使用 Selenium 和 Python 从 https ://www. twitch.tv/directory/game/Overwatch/clips?range=7d 中抓取前 10 个剪辑的 href 属性

java - 如何在使用 selenium 运行自动化测试时捕获互联网异常丢失

c# - 无法从下拉列表中选择元素