2016-11-18 1 views
1

hinzufügen Ich brauche, um Links auf meiner Website zu automatisieren. Ich möchte Xpath-Werte einmal in jeder Iteration der Schleife übergeben. Damit ich meine Codierung
public class Popup {Wie Looping-Bedingung für Selen-Java-Code

private WebDriver driver; 
    private String baseUrl; 
    //private boolean acceptNextAlert = true; 
    private StringBuffer verificationErrors = new StringBuffer(); 

    @Before 
    public void setUp() throws Exception { 
    driver = new FirefoxDriver(); 
    baseUrl = "http://www.example.com/info.php"; 
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    } 

    @Test 
    public void testPopup() throws Exception { 
    driver.findElement(By.xpath("//div[@id='info-list']/div[2]/div/div/div/div/a[2]/i")).click(); 
    driver.findElement(By.xpath("//div[@id='info-list']/div[2]/div/div/div/div/a[3]/i")).click(); 
    driver.findElement(By.xpath("//div[@id='info-list']/div[2]/div/div/div/div/a[4]/i")).click(); 
    driver.findElement(By.xpath("//div[@id='info-list']/div[2]/div/div/div/div/a[5]/i")).click(); 

Antwort

0

Können Sie versuchen, diese zu minimieren?

for(int j=2; j<=5; j++) { 
    driver.findElement(By.xpath("//div[@id='info-list']/div[2]/div/div/div/div/a["+j+"]/i")).click(); 
} 
0

Hallo Sanchit Khera Versuchen Sie dieses:

int i = 0; 

    //extract the link texts of each link element 
    for (WebElement e : linkElements) 
    { 
     linkTitles[i] = e.getText(); 
     i++; 
    } 

    //Test each link 
    for (String t : linkTitles) 
    {    
      // Titles Click 
      driver.findElement(By.linkText(t)).click();