A java + selenium questions about the positioning of the iframe

   A recent use java + selenium do a test. Encounter two problems, looking for answers to a long program. Finally resolved.

① The first problem is treated js event is not given reaction time before the popup.

        Specific Description: general access to network elements to refresh the basic method uses a smart waiting selenium acquisition. On this point no explanation. Affixed directly code reference.

private static WebElement getElement(WebDriver driver, String type, String value) {
return (WebElement) new WebDriverWait(driver, 60)
.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
switch (type) {
case "id":
return driver.findElement(By.id(value));
case "name":
return driver.findElement(By.name(value));
case "className":
return driver.findElement(By.className(value));
case "xpath":
return driver.findElement(By.xpath(value));
case "partialLinkText":
return driver.findElement(By.partialLinkText(value));
case "linkText":
return driver.findElement(By.linkText(value));
case "cssSelector":
return driver.findElement(By.cssSelector(value));
}
return null;
}
});

Above can solve network problems due to the positioning of page elements causes. However, because the network does not need js events that may have a relationship with the operating system reactions. and so,

I always find this element in dealing with the element of continuous js events. 1, id used for positioning, positioning is no problem; 2, iframe, and handle so as currently being processed

Range, positioning range is no problem.

In the end, we continue to rely on random testing, to obtain solutions. The final solution is to add the current thread to wait before js no event element positioning time to join the cause of the reaction system. Within one second

enough. But this must be a good time to join.

 

② The second problem is switched iframe Element not found.

    Specific description: Before positioning due to a iframe, now need to switch to another iframe. In any case always unsuccessful. Try to do the following:

      · Thread waits before switching

      Use the index switch

       ....................

    Ultimately we can not solve.

On the Internet for tips predecessors, and ultimately through his trials was a resolve.

        ※ provide a connection as follows

                https://wenku.baidu.com/view/969797ece518964bce847c12.html

The final solution is:

          Use before switching "driver.switchTo () defaultContent ();." Get back to the parent iframe, during the switch "driver.switchTo () frame (" xxxrame ");."

This revelation is like the same processing queue directory. It may be a bit similar and stack design.

As described in the above link predecessors (referenced, any questions please contact deleted)

  

Guess you like

Origin www.cnblogs.com/dengw125792/p/12106057.html