Java 硒罐';t将字段定位在帧内部

Java 硒罐';t将字段定位在帧内部,java,html,selenium,xpath,selenium-webdriver,Java,Html,Selenium,Xpath,Selenium Webdriver,我试图在一个框架内定位一个对象,但Selenium不断返回它在试图定位元素时超时的消息 以下是相关代码信息: 帧ID是tasks splash content。我使用这个方法调用SeleniumCommands.myDriver.switchTo().frame(“任务启动内容”) 我试图查找并向其发送密钥的字段id为txt\u dateof birth,xpath为html/body/table/tbody/tr/td/table/tbody/tr[1]/td/div/table/tbody/

我试图在一个框架内定位一个对象,但Selenium不断返回它在试图定位元素时超时的消息

以下是相关代码信息:

帧ID是
tasks splash content
。我使用这个方法调用
SeleniumCommands.myDriver.switchTo().frame(“任务启动内容”)

我试图查找并向其发送密钥的字段id为
txt\u dateof birth
,xpath为
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
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、面向数据的类和属性、或有意义的容器或邻居。

嗨,Alexe,谢谢您的帮助。那确实有效。我是否必须添加
SeleniumCommands.myDriver.switchTo().frame(“任务启动内容”)SeleniumCommands.myDriver.switchTo().defaultContent()
要回到主要内容吗?@lmcphers我想
SeleniumCommands.myDriver.switchTo().defaultContent()将使您返回初始默认内容(没有活动的iframe上下文)。很乐意帮忙!有没有办法从帧(0)内部返回帧?我尝试使用
SeleniumCommands.myDriver.switchTo().frame(“任务启动内容”)
返回一个帧,试图关闭该帧,但它无法从
frame(0)
@lmcphers中找到该帧。我想您必须转到默认内容,然后再次切换到
任务启动内容
。嘘,好的,谢谢!请原谅我的小错。:)