我正在尝试使用 vuetify 单击 vue js 中的按钮与 Selenium /katalon。它在 UI 中完全可见,但仍然可以单击。我可以毫无问题地找到该元素,但单击它会返回元素不可见错误。我尝试了各种solutions包括:
- 使用javascript点击(js执行点击脚本但不点击按钮)
- 使用 Action 类移动到该元素,然后单击它(它不会移动到该元素)
- 聚焦并滚动到元素
- 等待
- 切换到 Activity 元素、默认内容并最大化窗口
- 没有父元素且不显示
调试时我注意到以下内容:
// Able to find element with no issues
WebDriver driver = DriverFactory.getWebDriver();
String xPathForButton = "//div[@id='validationStepper']/div[3]/div[1]/div/div[2]/fieldset/div[1]/div/div/div/div[3]/button[1]";
def element = driver.findElement(By.xpath(xPath));
// Element not visible exception
element.click();
KeywordUtil.logInfo('X: ' + element.getLocation().x); // Prints 0
KeywordUtil.logInfo('Y: ' + element.getLocation().y); // Prints 0
KeywordUtil.logInfo('Element is enabled: ' + element.isEnabled()); // Prints true
KeywordUtil.logInfo('Element is displayed: ' + element.isDisplayed()); // Prints false
我需要使用 xpath 来查找这个元素。有人可以帮助我如何正确检测并单击此元素吗?
最佳答案
事实证明,问题是父元素在运行时为 display: none
。虽然我最初没有任何父元素,但 CSS 动态变化,导致这种情况发生。我进行了更正,然后该元素就可见了。
关于javascript - Katalon Selenium Element 可见但显示为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52177852/