[英]Selenium - Web Driver Wait
Here is what I normally write for finding an element with name =" email " 这是我通常为查找名为=“ 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排序中找到特定的WebElement,例如...
WebElement a = driver.findElement(By.id("KeepSmiling");
WebElement b = a.findElement(By.className("ChocolatesMakeMeSizzle");
Here b
is an element within a
. 这里
b
是内的元素a
。 Since there are many other div with className -> ChocolatesMakeMeSizzle 由于还有许多其他的className-> ChocolatesMakeMeSizzle
I wish to do the same but with WebDriverWait
. 我希望使用
WebDriverWait
进行相同的操作。 I avoid this issue using Thread.sleep(xx)
but its a really bad method. 我使用
Thread.sleep(xx)
避免了这个问题,但这是一个非常糟糕的方法。
Here is what I tried (but I realized that Im trying to slow down a webElement which makes no sense). 这是我尝试过的方法(但是我意识到我试图降低没有意义的webElement)。
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). 自白:老实说,我避免使用此方法,而是使用Thread.sleep(xx)。
I am able to use the xpath and find the way but I am hoping for an answer to my question! 我可以使用xpath并找到方法,但是我希望能回答我的问题! :)
:)
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. 如果DOM上存在元素,那么Modal应该不会有问题。 I'm testing a big system and all the forms are modal, we dont have any problem to find the element using ExpectedConditions.
我正在测试一个大型系统,并且所有形式都是模式形式的,我们使用ExpectedConditions查找元素没有任何问题。
Also, for finding you can use XPATH... 此外,要找到您可以使用XPATH ...
here's a example: //input[contains(@class, 'name')]/following::input[@type='Button'] 这是一个示例:// input [contains(@class,'name')] / following :: input [@ type ='Button']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.