Reputation: 787
Here is what I normally write for finding an element with name =" email "
WebElement emailInput = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By
.name("email")));
What if there is an element modal body as seen below
WebElement modalBody = enrollForm.findElement(By
.className("modal-body"));
Now, if I was to find a specific WebElement within another WebElement sorta like...
WebElement a = driver.findElement(By.id("KeepSmiling");
WebElement b = a.findElement(By.className("ChocolatesMakeMeSizzle");
Here b
is an element within a
. Since there are many other div with className -> ChocolatesMakeMeSizzle
I wish to do the same but with WebDriverWait
. I avoid this issue using Thread.sleep(xx)
but its a really bad method.
Here is what I tried (but I realized that Im trying to slow down a webElement which makes no sense).
WebElement emailInput = (new WebDriverWait(modalBody, 10))
.until(ExpectedConditions.presenceOfElementLocated(By
.name("email")));
Any tips how to achieve this?
Confessions: I honestly was avoiding this method and using Thread.sleep(xx).
I am able to use the xpath and find the way but I am hoping for an answer to my question! :)
Upvotes: 0
Views: 174
Reputation: 159
WebElement emailInput = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By
.xpath("some_complex_xpath")));
If the element is present on the DOM, you should not have a problem with the Modal. I'm testing a big system and all the forms are modal, we dont have any problem to find the element using ExpectedConditions.
Also, for finding you can use XPATH...
here's a example: //input[contains(@class, 'name')]/following::input[@type='Button']
Upvotes: 3