我正在尝试从输入字段中删除一个值并保存更改。我在单击“保存”按钮时遇到问题。这在所有其他测试中都有效,只有在这里不起作用。可能是因为表单很长,我需要滚动直到元素可见。我已经搜索并尝试了这里的大部分建议,但没有任何效果。这是我的代码:
//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/