In my web page, when I click OK button, some HTML tag will be added in current page source for display popup (the URL is not changed).
How can I get new web element from current page?
Asked
Active
Viewed 1,422 times
-1

Duong Anh
- 529
- 1
- 4
- 21
-
Are you looking for a way to find any new element which was created due to click of OK button? Or do you want to search for a specific element after clicking on OK button? – Kamal Jan 16 '19 at 09:56
-
I want to search for a specific element after clicking on OK button – Duong Anh Jan 16 '19 at 10:14
-
Then @Guy's answer should work for you, if it does not then share the error you get. – Kamal Jan 16 '19 at 10:16
-
I tried but the exception is "Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element" – Duong Anh Jan 16 '19 at 10:19
-
Then please share the html code of that element(check if it is in an iframe tag), and also share the code which you used(the locator) – Kamal Jan 16 '19 at 10:21
-
The html tag which has been added is div tag – Duong Anh Jan 16 '19 at 10:26
-
@Kamal Thanks for your support. The problem is in my html code. – Duong Anh Jan 16 '19 at 10:30
1 Answers
2
You can use explicit wait to wait for the element to be added to the DOM
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("newElementId")));

Guy
- 46,488
- 10
- 44
- 88