无法点击 iframe 内的元素

Pur*_*ath 2 iframe selenium click

下面的屏幕上是 iframe 的 HTML 代码。

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

请帮助我单击框架内的提交按钮。 在此输入图像描述

Ric*_*ard 5

您需要使用来访问 a或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
Run Code Online (Sandbox Code Playgroud)

根据您的具体情况,您可以使用:

driver.switchTo().frame("InstantSgn");
Run Code Online (Sandbox Code Playgroud)

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

driver.switchTo().defaultContent();
Run Code Online (Sandbox Code Playgroud)