简体   繁体   English

硒无法找到框架内的字段

[英]Selenium Can't Locate Field Inside of Frame

I am trying to locate an object inside of a frame, but Selenium keeps returning that it timed out trying to locate the element. 我正在尝试在框架内定位对象,但是Selenium一直在返回它试图定位元素超时的返回信息。

Here is the relevant code information: 以下是相关的代码信息:

The frame ID is tasks-splash-content . 框架ID为tasks-splash-content I am switching to it with this method call SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content"); 我正在使用此方法调用SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content");切换到它SeleniumCommands.myDriver.switchTo().frame("tasks-splash-content");

The field I am trying to locate and send keys to has an id of txt_dateofbirth and xpath of html/body/table/tbody/tr/td/table/tbody/tr[1]/td/div/table/tbody/tr/td/table/tbody/tr[4]/td[1]/input[1] . 我尝试查找并发送密钥的字段的ID为txt_dateofbirth ,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] So far, both selection methods have not worked for me. 到目前为止,这两种选择方法都不适用于我。

Here is the function body of my method that finds an element by xpath wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath))); 这是我的方法的函数体,它通过xpath来查找元素wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));

So, sequentially, I am switching to the frame, waiting until the field is visible, and then trying to send it some values. 因此,依次地,我切换到框架,等待该字段可见,然后尝试向其发送一些值。 Does anyone know what might be causing this to not work for me? 有谁知道这可能导致它不适用于我?

Frame HTML: 框架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>

There is a nested iframe you need to search in: 您需要在其中搜索嵌套的iframe

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

Also, note that the XPath expression you've presented is not quite reliable, try to rely on ids, data-oriented classes and attributes, or meaningful containers or neighbors. 另外,请注意,您提供的XPath表达式不太可靠,请尝试依赖id,面向数据的类和属性或有意义的容器或邻居。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM