- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我用java代码为iframe定位器创建了一个循环但它不起作用。谁能看出问题所在吗?
调用类:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement searchButton = IFrameLocator.switchToIFrameWithElement(driver,driver.findElement(By.cssSelector("[href*='Search.mvc'][class*='magnify']")));
and use this after:
searchButton.click();
public class IFrameLocator {
public static WebElement switchToIFrameWithElement(WebDriver driver, WebElement element) {
try {
driver.switchTo().defaultContent();
element.isDisplayed();
} catch (Exception continueFlow) {
WebDriverWait wait = new WebDriverWait(driver, 20);
List<WebElement> frames = driver.findElements(By.cssSelector("iframe"));
for (WebElement frame : frames) {
driver.switchTo().defaultContent();
try {
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frame));
if (element.isDisplayed()) {
break;
}
} catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException ignored) {
}
}
} return element;
}
}
最佳答案
因为我通过 cssSelector 传递了整个 Webelement,所以它甚至没有进入循环。所以我像这样传递元素:
WebElement searchButton = IFrameLocator.switchToIFrameWithElement(driver, By.cssSelector("[href*='Search.mvc'][class*='magnify']"));
所以我更改了代码并删除了 2 个位置的 By.cssSelector,现在一切正常:
公共(public)类 IFrameLocator {
public static WebElement switchToIFrameWithElement(WebDriver driver, By element) {
driver.switchTo().defaultContent();
try {
if (driver.findElement(element).isDisplayed()) ;
{
System.out.println("Element is displayed on main page");
}
} catch (Exception continueFlow) {
List<WebElement> frames = driver.findElements(By.cssSelector("iframe"));
for (WebElement frame : frames) {
driver.switchTo().defaultContent();
System.out.println("going back to main page");
try {
driver.switchTo().frame(frame);
System.out.println("switched to next frame: " + frame);
if (driver.findElement(element).isDisplayed()) {
System.out.println("element is found in frame: " + frame);
break;
}
} catch (NoSuchElementException | StaleElementReferenceException | ElementNotInteractableException ignored) {
}
}
} System.out.println("returned element succesfully");
return driver.findElement(element);
}
}
关于java - 用于定位 iram 并切换到它的循环不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56653583/
我用java代码为iframe定位器创建了一个循环但它不起作用。谁能看出问题所在吗? 调用类: driver.manage().timeouts().implicitlyWait(20, TimeUn
我有一个由各个 Soundcloud 轨道的帖子组成的 WordPress 网站,当上一首轨道播放完毕时,我需要播放下一首轨道(在下一篇文章中),因为我的主页是用最新帖子制作的。 我尝试了很多js函数
我必须让我的设备从 Linux 2.6.38 进入非常低的低功耗模式,因此,有必要暂停所有组件,包括 CPU 和 DDR2。 到目前为止我发现我必须将核心汇编程序函数复制到处理器的内部存储器中并从那里
我都尝试过 iframe - 没有解决方案来停止自动播放或控制非 YouTube 视频的视频 视频 - 不支持 YouTube 视频 使用 iframe jQuery(document).read
我是一名优秀的程序员,十分优秀!