java - Selenium 无法定位帧内的字段

标签 java html selenium xpath selenium-webdriver

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

以下是相关代码信息:

框架 ID 为 tasks-splash-content 。我正在使用此方法调用 SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content"); 切换到它

我尝试查找并向其发送 key 的字段的 ID 为 txt_dateofbirthhtml/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/

相关文章:

Windows 8 上的 Eclipse 兼容性

html - 响应式导航菜单的字体大小问题

html - HTML 中 "name"属性的有效值

mysql - 如何告诉 Selenium 使用测试数据库?

java - 如何避免自动更改 .CSV 文件中的数据类型

java - 当n个人围成一圈时寻找幸存者

java - Gradle 使用不同的资源和类进行多次 war

html - 获取右侧的页脚链接并与左侧的文本对齐

python - Selenium 无法启动 Firefox

css - Selenium Webdriver XPATH 我可以找到包含某些文本的标签,但我无法在标签标签上方获得输入标签复选框