Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 硒没有识别';iframe';_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

Selenium 硒没有识别';iframe';

Selenium 硒没有识别';iframe';,selenium,selenium-webdriver,webdriver,Selenium,Selenium Webdriver,Webdriver,下面是我的代码 driver.switchTo().frame(driver.findElement(By.id("file"))); 上面的行未运行切换到帧有多种方式。如果您需要确切的代码切换到各自的应用程序,请共享HTML代码。你可以试试下面的方法。如果你的框架没有任何名称等,最好使用索引 driver.switchTo().frame(index) 首先将索引替换为0,如果它不起作用,则依次尝试使用1和2等 更多细节 driver.switchTo().frame()具有多个重载 dr

下面是我的代码

driver.switchTo().frame(driver.findElement(By.id("file")));

上面的行未运行

切换到帧有多种方式。如果您需要确切的代码切换到各自的应用程序,请共享HTML代码。你可以试试下面的方法。如果你的框架没有任何名称等,最好使用索引

driver.switchTo().frame(index)
首先将索引替换为0,如果它不起作用,则依次尝试使用1和2等

更多细节

driver.switchTo().frame()
具有多个重载

driver.switchTo().frame(name or id) 
这里您的iframe没有id或名称,因此不适合您

driver.switchTo().frame(index) 
这是最后一个选择,因为使用索引并不像您想象的那样足够稳定。如果这是页面中唯一的iframe,请尝试

driver.switchTo().frame(0)

最常见的一个。您可以像其他元素一样定位iframe,然后将其传递到方法中

在这里,按标题属性定位它似乎是最好的

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title='Fill Quote']")));
// driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[@title='Fill Quote']")));

最可能的情况是,iframe不可见或窗口未处于活动状态

在Python中:

    driver.switch_to_default_content()
    wait.until(EC.frame_to_be_available_and_switch_to_it("yourFrame"))
在Java中:

driver.switchTo().defaultContent();
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("yourFrame")));

下面是源代码,请发布HTML代码片段和您尝试使用的框架的完整代码。
driver.switchTo().defaultContent();
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.tagName("yourFrame")));