尽管我有明确的等待,但我不断收到“元素不可交互”的信息

我正在使用Selenium脚本,并且可以正常工作直到最后一步-验证面板右上方的绿色“比较”按钮上有文字“比较(1)”。尽管我有明确等待,但我的eclipse一直给我“元素不可交互”。

即使在脚本中包含“显式等待”之前,我仍然不断收到此“元素不可交互”错误。 Xpath在Inspect->按字符串查找,选择器或xpath栏上的站点上可以正常工作。我最初没有使用显式等待。这是我在包括WebDriver Wait之前执行此步骤的代码:String compareButton = driver.findElement(By.xpath("(//button[@class='btn btn-default button button-medium bt_compare bt_compare']/ancestor::form)[1]")).getText(); 我尝试使用不同的xpaths / locator,在Inspect中可以正常工作,但始终出现相同的错误。我研究了这个问题,并且大多数在线建议(包括Stack Overflow在内)都表示元素可能不可交互,因为它不可见,因此建议使用WebDriver Wait进行建议(这就是为什么我当前的代码具有等待条件的原因... ),但即使稍候,我也会收到错误消息。我尝试使用其他等待方法/条件,例如“ elementToBeclickable”,但没有任何效果。

@Test
public void Product_Compare()  {
//      Go to http://www.automationpractice.com
        driver.get(AppProperties.AUTOMATION_PRactICE_BASE_URL);

//      Enter 'Dress' in search text box on top
        driver.findElement(By.cssSelector("#search_query_top")).sendKeys("Dress");

//      Click on search button icon
        driver.findElement(By.cssSelector("button.btn.btn-default.button-search")).click();

//      Click 'Add to Compare' link for first product
        driver.findElement(By.xpath("(//a[@title='Printed Summer Dress']/ancestor::li//a[text()='Add to Compare'])[1]")).click();

//      Verify On top right of panel,Green Compare button has text 'Compare (1)' 
        WebDriverWait waitForCompareButton = new WebDriverWait(driver,30);
        WebElement greenCompareButton;
        greenCompareButton = waitForCompareButton.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("\"(//button[@class='btn btn-default button button-medium bt_compare bt_compare']/ancestor::form)[1]\"")));  

        System.out.println("Green Compare button has text: " + greenCompareButton.getText());
        Assert.assertEquals("Compare (1)",greenCompareButton.getText());
sunonxg 回答:尽管我有明确的等待,但我不断收到“元素不可交互”的信息

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3068615.html

大家都在问