I will start by saying that I am new to Selenium and also to Java. I installed Selenium IDE, recorded some steps and modified this basic test and executed it as JUnit test within Eclipse. I was able to get something basic running against IE 11. However, I'm having a problem with Selenium clicking on an element. Another element that works, seems very similar so I don't understand what the problem is. Below is the InspectElement results from IE for the page I am working with in our app.
The findElement for the "Add Substation" towards the bottom of my code below works fine. The findElement for the "Delete Substation" that follows doesn't work. I've tried multiple things and can't figure it out. Again, I am quite new to Java and Selenium, so it may be something obvious to many of you...just not to me.
Below is a portion of the code I am running: //#######################################################################
public class UMS_test_1 {
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
public void setUp() throws Exception {
// Set path of IEDriverServer.exe.
// Note : IEDriverServer.exe should be In C: drive.
System.setProperty("webdriver.ie.driver", "C://IEDriverServer.exe");
// Initialize InternetExplorerDriver Instance.
WebDriver driver = new InternetExplorerDriver();
baseUrl = "https://10.10.10.10:8443/";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void testTry1SeleniumIDEJunitExport() throws Exception {
System.setProperty("webdriver.ie.driver", "C://IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
//baseUrl = "https://10.10.10.10:8443/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("continueToSite")).click();
driver.get(baseUrl + "/ams/login");
driver.findElement(By.name("j_username")).clear();
driver.findElement(By.name("j_username")).sendKeys("xxxxxxx");
driver.findElement(By.name("j_password")).clear();
driver.findElement(By.name("j_password")).sendKeys("xxxxxxx");
driver.findElement(By.id("loginSubmit")).click();
Thread.sleep(1000);
driver.findElement(By.linkText("Add Substation")).click();
...
Thread.sleep(5000);
driver.get(baseUrl + "/ams/substations_circuits");
driver.findElement(By.linkText("Delete Substation")).click();
//#######################################################################
Here is the error I receive:
org.openqa.selenium.NoSuchElementException: Unable to find element with link text == Delete Substation (WARNING: The server did not provide any stacktrace information)
I Googled and tried multiple solutions, but couldn't fix the problem. I did find some code to print out the table elements and the Delete is returned as part of the list, so I don't understand why I can't find the Delete and click on it. Here's the debug code I added:
//Code to loop through table and print contents (WORKING)
Thread.sleep(15000);
WebElement table_element = driver.findElement(By.id("subTable"));
List<WebElement> rows = table_element.findElements(By.xpath("id('subTable')/tbody/tr"));
java.util.Iterator<WebElement> i = rows.iterator();
while(i.hasNext()) {
WebElement row = i.next();
System.out.println(row.getText());
}
Here are the results of debug code being run:
Add Substation
mmm Providence RI Edit RTU Edit Hands On Disabled Settings Delete
I should also note that I recorded this in Firefox with Selenium IDE to generate most of the code.
The only thing that comes to mind is that there are only two rows in the subTable, Add Substation is the first and only element in the first row, Delete Substation is the last of many elements in the second row. I think this may be part of the problem, but I'm not sure how to get around it.
Thanks in advance for any suggestions.