我写了一个代码来切换到框架并将一些值发送到文本框。在编写代码时它对我有用。现在它正在识别对象并且它没有传递值。请让我知道它为什么失败。
Getobject 方法使用 xpath 查找元素,xpath 存储在属性文件中。
getobject("ForgotClaimNumber_Link").click();
driver.switchTo().frame(driver.findElement(By.id("fancybox-frame")));
WebDriverWait wait = new WebDriverWait(driver,100);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id='txtClaimNum']")));
getobject("ClaimNumber_Edit").sendKeys("5200098863");
getobject("Find_Button").click();
最佳答案
我认为您需要先切换到框架,然后才能向其发送其他命令。不要认为您可以切换到一个框架,然后在一个命令中使用 find 元素。您将需要知道框架名称或 ID。一旦你知道你可以执行操作。完成框架后,您需要返回主窗口(退出框架)
driver.switchTo().frame("在此处输入 ID 或名称");
driver.findElement(By.id("ID"));
关于iframe - selenium webdriver 无法识别 iframe 中的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993275/