java - how to select 2nd button using selenium code if 3 buttons are same -


error when select 1 of them

i have 3 button , wants select 2nd 1 using selenium testing java code

<p>         <button class="btn btn-primary pull-right" ng-click="openmediacreator=true">add</button>     </p>     <p>     <button class="btn btn-primary pull-right" ng-click="openmediacreator=true">add</button>     </p>     <p>     <button class="btn btn-primary pull-right" ng-click="openmediacreator=true">add</button>     </p> 

i use code select 2nd button

public basketdetailsobject addyoutubevideo(string url){         try {             getdriver().findelement(by.linktext("add")).click();         } catch (exception e) {             system.out.println("there error on add youtube video"+e);         }         return getfactory().create(basketdetailsobject.class);     } 

but knw not works please give me wright code that

use this, need ensure have 3 buttons otherwise get(1) may fails or give wrong button.

list<webelement> buttons = getdriver().findelements(by.linktext("add")); buttons.get(1).click(); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -