查找非活动元素(Javascript)并仅单击非活动元素Selenium Java

时间:2018-01-14 10:33:47

标签: javascript java selenium

public void inactive throws exceptions ()
{
    List<WebElement> myElements = driver.findElements(By.xpath("/html/body/div[2]/div[6]/div/table"));
    System.out.println("Size of List: " + myElements.size());
    for (WebElement e : myElements) {

        System.out.print("Text within the Anchor tab" + e.getText() + "\t");
        System.out.println("Anchor: " + e.getAttribute("href"));

        ((JavascriptExecutor) driver).executeScript("scroll(0,400)").equals("href=\"javascript:toggleEnabled");
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(text(), 'Inactive")));

    }

我无法找到非活动元素(a.herf)并仅点击特定的非活动元素。如何在toggle.Enabled JavaScript上找到该元素,并仅点击title = "Inactive"状态表单列表? HTML控制台代码如下所述。

<a href="javascript:toggleEnabled('Collaboration Browse -> Browse');">
    <img src="/console/themes/images/new_imgs/status_light_off.png" 
         style="width:24px; height:24px;" alt="Inactive" title="Inactive">
</a>

1 个答案:

答案 0 :(得分:0)

我理解你的问题,试试这个:

List<WebElement> list = driver.findElements(By.xpath(".//a/img[@title='Inactive']"));

list.forEach(WebElement::click);