Accept alert box

90 views
Skip to first unread message

Dimuth Lasantha

unread,
Nov 3, 2014, 12:54:08 AM11/3/14
to seleniu...@googlegroups.com
i implemented do while loop to my test case and then alert box confirmation is not working. before implement the do while loop it worked fine. bellow i have mentioned the code 

try{

int count = 1;

do{

driver.findElement(By.xpath(".//*[@id='item_list']/li[" + count + "]/ul/li[3]/div")).click();

count++;

}

while(driver.findElement(By.xpath(".//*[@id='item_list']/li[1]/ul/li[5]/div/span")).getText().toString().equals("CLOSED"));

driver.findElement(By.xpath(".//*[@id='js_single_statement']/div[1]/header/div/ul[2]/li[2]/a")).click();

driver.findElement(By.cssSelector(".menu_group .rlink")).click();

driver.switchTo().alert().accept();

}catch(Exception e){

Reporter.log("Invoice list is empty");

}

Ravindra

unread,
Nov 4, 2014, 1:11:43 AM11/4/14
to seleniu...@googlegroups.com
Hi Dimuth,
                Code seems fine, but it may be the case that you are accidentally putting some statement at incorrect place.
If possible please provide the scenario and the Exception you are seeing at Console.


Regards,
~Ravindra

Dimuth Lasantha

unread,
Nov 4, 2014, 1:24:49 AM11/4/14
to seleniu...@googlegroups.com
HI Ravindra, 

there was a small  mismatch of my code. and now it is working fine for me. here i have mentioned the correct code.

public void closeInvoice(){

driver.findElement(By.xpath(".//*[@id='invoices']/a")).click();

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

try{

int count = 1;

do{

count++;

}

while(driver.findElement(By.xpath(".//*[@id='item_list']/li[" + count + "]/ul/li[5]/div/span")).getText().toString().equals("CLOSED"));

driver.findElement(By.xpath(".//*[@id='item_list']/li[" + count + "]/ul/li[5]/div/span")).click();

//Get label name

label_name = driver.findElement(By.xpath(".//*[@id='inv_sum']/dt/span")).getText().toString();

driver.findElement(By.xpath(".//*[@id='js_single_statement']/div[1]/header/div/ul[2]/li[2]/a")).click();

driver.findElement(By.xpath(".//*[@id='js_single_statement']/div[1]/header/div/ul[2]/li[2]/ul/li[11]/a")).click();

driver.switchTo().alert().accept();

WebDriverWait wait = new WebDriverWait(driver, 30); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("closed_tag")));

}catch(Exception e){

Reporter.log("Invoice list is empty");

}

}


On Monday, November 3, 2014 11:24:08 AM UTC+5:30, Dimuth Lasantha wrote:

Muralisankar A

unread,
Nov 4, 2014, 8:34:04 AM11/4/14
to seleniu...@googlegroups.com
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


public class Testcases {
   
    WebDriver driver;
    String baseurl="http://192.168.0.190/users/login/";
   
    @BeforeTest
    public void setup() {
       
        driver=new FirefoxDriver();
        driver.get(baseurl);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    }
     @Test
      public void TC8() {
         
          driver.findElement(By.id("id_username")).sendKeys("admin");
          driver.findElement(By.id("id_password")).sendKeys("admin");
          driver.findElement(By.cssSelector("button,input[type='button']")).click();
          Reporter.log("TC101 > Login successfully to crossfraudet");
      }
     
     @Test
     public void TC9() {
           
          driver.findElement(By.cssSelector(".icon-users"));
             
     }
      @Test
      public void TC10() {
       
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
          driver.findElement(By.cssSelector(".icon-users")).click();
          driver.findElement(By.cssSelector("#menuList > li.dropdown.open > ul > li:nth-child(3) > a")).click();
          Reporter.log("TC102 > Click on User Profile > Profiles");  
         
      }
     
   
}

[TestNG] Running:
  C:\Users\Murali\AppData\Local\Temp\testng-eclipse-769164162\testng-customsuite.xml

PASSED: TC8
PASSED: TC9
FAILED: TC10
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"css selector","selector":".icon-users"}
Command duration or timeout: 10.04 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html



How can I solve this issue? Anybody please help me

Dimuth Lasantha

unread,
Nov 4, 2014, 9:18:44 AM11/4/14
to seleniu...@googlegroups.com
Can u try with this code part . Add this code to TC9()

WebDriverWait wait = new WebDriverWait(driver, 30); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users")));


Like this 

 @Test
     public void TC9() {
            
          driver.findElement(By.cssSelector(".icon-users"));

          WebDriverWait wait = new WebDriverWait(driver, 30); 

          wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users")));


             
     }

As well as Why are u use TC9() method, it is only select the element. you are not using it.



--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/iOnoRAwOB6A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/43a4df0a-87d6-42f3-a043-648b35544a45%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Dimuth Lasantha
Vesess Inc 

Muralisankar A

unread,
Nov 4, 2014, 9:42:26 AM11/4/14
to seleniu...@googlegroups.com
hi dimuth, thanks for your reply. It shows the timeout exception now


@Test
       public void TC9() {
         WebDriverWait wait = new WebDriverWait(driver, 30);
              wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users")));
         }

      @Test
      public void TC10() {

        WebDriverWait wait = new WebDriverWait(driver, 30);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users")));
        driver.findElement(By.cssSelector(".icon-users")).click();
        driver.findElement(By.cssSelector("#menuList > li.dropdown.open > ul > li:nth-child(3) > a")).click();
        Reporter.log("TC102 > Click on User Profile > Profiles"); 
      }


PASSED: TC8
PASSED: TC9
FAILED: TC10
org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for visibility of element located by By.selector: .icon-users
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'
System info: host: 'BDMAGFPC009', ip: '192.168.12.118', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.firefox.FirefoxDriver



Muralisankar A

unread,
Nov 4, 2014, 11:03:28 AM11/4/14
to seleniu...@googlegroups.com

Dimuth Lasantha

unread,
Nov 4, 2014, 11:55:20 AM11/4/14
to seleniu...@googlegroups.com
You no need to place the code in both methods. 
meaning of the code part :- it wait 30 seconds till load the element (css selector). 
some times it may take more time than 30 second or it may not find the element. can u try with xpath or check css selector again. 

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/iOnoRAwOB6A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Muralisankar A

unread,
Nov 5, 2014, 5:29:24 AM11/5/14
to seleniu...@googlegroups.com
Hi dimuth,


@Test
      public void TC8() {
         
          driver.findElement(By.id("id_username")).sendKeys("admin");
          driver.findElement(By.id("id_password")).sendKeys("admin");
          driver.findElement(By.cssSelector("button,input[type='button']")).click();
          Reporter.log("TC101 > Login successfully to crossfraudet");
         
      }
     @Test
     public void TC9() {
       
         Assert.assertEquals("USER PROFILE", "USER PROFILE");
         Assert.assertEquals("SETTINGS", "SETTINGS");
         Assert.assertEquals("DASHBOARD", "DASHBOARD");
         Assert.assertEquals("ADMINISTRATION", "ADMINISTRATION");
     }
      @Test
      public void TC10() {

        wait=new WebDriverWait(driver,30);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(".icon-users"))).click();
        wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#menuList > li.dropdown.open > ul > li:nth-child(3) > a"))).click();
        Reporter.log("TC10 > Click on User Profile > Profiles");  
         
      }

[TestNG] Running:
  C:\Users\Murali\AppData\Local\Temp\testng-eclipse-609099432\testng-customsuite.xml


PASSED: TC8
PASSED: TC9
FAILED: TC10
org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for visibility of element located by By.selector: .icon-users
Build info: version: '2.43.1', revision: '5163bce', time: '2014-09-10 16:27:33'


It shows the above error. If I use driver.findElement it shows No such element exception. If I user wait.until(ExpectedCondition.presenceOfElementLocated), it shows timeoutexception. How could I solve this issue



Reply all
Reply to author
Forward
0 new messages