Selenium 无法定位框架内的字段

Selenium Can't Locate Field Inside of Frame

我试图在框架内定位对象,但 Selenium 一直返回它在尝试定位元素时超时。

这里是相关代码信息:

帧 ID 为 tasks-splash-content。我正在通过此方法调用 SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content");

切换到它

我试图定位并向其发送密钥的字段具有 txt_dateofbirth 的 ID 和 html/body/table/tbody/tr/td/table/tbody/tr[1]/td/div/table/tbody/tr/td/table/tbody/tr[4]/td[1]/input[1] 的 xpath。到目前为止,这两种选择方法都不适合我。

这是我的方法的函数体,它通过 xpath 找到一个元素 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));

因此,我依次切换到框架,等待字段可见,然后尝试向其发送一些值。有谁知道可能导致这对我不起作用的原因?

帧HTML:

<div id="tasks-splash-window" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 638px; padding: 0px;" scrolltop="0" scrollleft="0">
<iframe id="tasks-splash-content" scrolling="no" frameborder="0" src="https://qa3.jobappdemo.com/apply/c_tca/l_en/applied/OpenForms.cfm?dr=i9&hp=1204988&fid=401">
<html>
<head></head>
<body>
<iframe width="890" height="635" frameborder="0" src="https://qa3.jobappdemo.com/jobapp/get_appl_i9.cfm?hired_profile_id=1204988&hired_id=1204930&i9_id=902486&lang=en&new=1&rnd=327">
</body>
</html>
</iframe>
</div>
</div>

有一个嵌套的iframe您需要搜索:

SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content");
SeleniumCommands.myDriver.switchTo().frame(0);  // switch to the very first iframe

另外请注意,您提供的 XPath 表达式不太可靠,请尝试依赖 id、面向数据的 类 和属性,或有意义的容器或邻居。