簡體   English   中英

需要一個復雜的cssSelector來區分同一頁面上的兩個保存按鈕

[英]Need a complex cssSelector to differentiate between two save buttons on same page

我在同一頁面上有兩個保存按鈕,但是我需要單擊底部的一個。

這是第一個:

 <a href="javascript:addPhoneNumber('edit')">
 <img width="60" height="19" border="0" title="Save" alt="Save" src="../images/save.gif">

這是第二個:

 <a href="javascript:onSave()">
 <img width="60" height="19" border="0" title="Save" alt="Save" src="../images/save.gif">

我需要單擊第二個。 我嘗試了這個但沒有骰子:

 WebElement foo5 = (new WebDriverWait(driver, 30))
       .until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href*='javascript:onSave()'][alt='Save']")));
 foo5.click();

有指針嗎? 我對cssselectors感到恐懼。

嗨,請像下面這樣

public static void main(String[] args) {
        WebDriver driver = new SafariDriver();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        // as both button have same title so take them inside the list 
        List<WebElement> mybuttons = driver.findElements(By.cssSelector("a[type='Save']"));
        // Now to verify total number of buttons with type attribute as save
        System.out.println("Total buttons on the page is : " +mybuttons.size());

        // now we can click buttons on the basis of index as they are inside the 
        // List now Note in java index starts form zero (0)

        mybuttons.get(0).click();  // to click on the First button
        mybuttons.get(1).click();  // to click on the Second button
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM