Skip to content

Commit 168ebe4

Browse files
committed
Fix for element not found exception
1 parent 2c0c8ca commit 168ebe4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.project
55
/.settings/
66
/bin/
7-
MANIFEST.MF
7+
MANIFEST.MF
8+
.idea

src/main/java/stepDefinitions/ToDoStepDefinition.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package stepDefinitions;
22

3+
import org.openqa.selenium.*;
34
import org.openqa.selenium.By;
45
import org.openqa.selenium.remote.RemoteWebDriver;
56
import org.testng.Assert;
@@ -14,33 +15,38 @@ public class ToDoStepDefinition extends TestRunner {
1415

1516

1617
@Given("^user is on home Page$")
17-
public void user_already_on_home_page() {
18+
public void user_already_on_home_page() throws InterruptedException {
1819
System.out.println(driver.getCapabilities());
1920
driver.get("https://lambdatest.github.io/sample-todo-app/");
20-
21+
Thread.sleep(5000);
2122
}
2223

2324
@When("^select First Item$")
2425
public void select_first_item() {
25-
driver.findElement(By.name("li1")).click();
26+
WebElement li = driver.findElement(By.name("li1"));
27+
li.click();
2628
}
2729

2830
@Then("^select second item$")
2931
public void select_second_item() {
30-
driver.findElement(By.name("li2")).click();
32+
WebElement li = driver.findElement(By.name("li2"));
33+
li.click();
3134
}
3235

3336
@Then("^add new item$")
34-
public void add_new_item() {
35-
driver.findElement(By.id("sampletodotext")).clear();
37+
public void add_new_item() throws InterruptedException {
38+
WebElement text = driver.findElement(By.id("sampletodotext"));
39+
text.clear();
3640
driver.findElement(By.id("sampletodotext")).sendKeys("Yey, Let's add it to list");
41+
Thread.sleep(1000);
3742
driver.findElement(By.id("addbutton")).click();
43+
Thread.sleep(2000);
3844
}
3945

4046
@Then("^verify added item$")
4147
public void verify_added_item() {
4248
String item = driver.findElement(By.xpath("/html/body/div/div/div/ul/li[6]/span")).getText();
43-
Assert.assertTrue(item.contains("Yey, Let's add it to list"));
49+
Assert.assertTrue(item.contains("Yey, Let's add it to list"), "Expected : Yey, Let's add it to list Actual : " + item);
4450
}
4551

4652

0 commit comments

Comments
 (0)