我试图在框架内定位一个对象,但 Selenium 不断返回尝试定位该元素超时的消息。
以下是相关代码信息:
框架 ID 为 tasks-splash-content
。我正在使用此方法调用 SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content");
切换到它
我尝试查找并向其发送 key 的字段的 ID 为 txt_dateofbirth
和 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 表达式不太可靠,请尝试依赖 ids、面向数据的类和属性,或者有意义的容器或邻居。
关于java - Selenium 无法定位帧内的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31617591/