无法点击iframe中的元素

时间:2014-05-21 17:16:15

标签: selenium iframe click

下面的屏幕截图是iframe的HTML代码。

前两个红色标记的对象可以通过Webdriver识别,但Webdriver不能单击最后标记的对象(这是一个按钮)。我试过用不同的方式点击它(比如点击ID,名字等)。但我仍然无法点击提交按钮。

请帮我点击框内的提交按钮。 enter image description here

2 个答案:

答案 0 :(得分:3)

您需要使用switchTo().frame()来访问frameiframe内的内容。

driver.switchTo().frame("name");  // where name is the name of the iframe i.e. name="frameName", you would use framename
driver.switchTo().frame(0);       // You can switch to the frame by index
driver.switchTo().frame(element); // You can switch to the frame by a WebElement reference

在您的特定情况下,您可以使用:

driver.switchTo().frame("InstantSgn");

iframe上下文中完成后切换出框架:

driver.switchTo().defaultContent();

答案 1 :(得分:0)

今天我遇到了同样的问题。可能是由于您没有切换到相框,或者是我经历过的事情。

这仅发生在IE中。在Chrome中根本没有问题。

Actual Code

如您所见,我确实切换到框架以确保可以找到此元素。但是,事实并非如此。我发现的唯一解决方案是将Thread.Sleep(2000)通过。我不太清楚为什么,但是我想这与DOM中无法提供的内容有关。

相关问题