2016-05-23 6 views
0

同じページに2つの保存ボタンがありますが、下のものをクリックする必要があります。同じページの2つの保存ボタンを区別するために複雑なcssSelectorが必要

これが最初である:

<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"> 

は、私は2番目のいずれかをクリックする必要があります。私はこれを試してみましたが、ダイスはありませんでした:

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

すべてのポインタはありますか?私はcssselectorsには恐ろしいです。

答えて

2

こんにちは

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 
    } 
+0

おかげで以下のようにそれをしてください!それはうまくいった。 –

+0

嬉しいことに、それはあなたに役立った –