_小海 2019-08-30 19:24 采纳率: 0%
浏览 481
已结题

java爬虫,selenium切换到子类iframe失败

我在用java+selenium+chromewebdriver爬数据的时候,
这个网站frame内的table表格内又嵌套了iframe,我不知道为什么我无法通过
switchto().frame(id)获取其他方法定位到此iframe。求大佬解惑

 WebDriver webDriver = getWebDriver("dataUrls");

        try {
            TimeUnit.SECONDS.sleep(2);
            WebDriver driver = webDriver.switchTo().frame("SI2_mem_index");
            driver.findElement(By.id("username")).sendKeys("jv39737");
            driver.findElement(By.id("passwords")).sendKeys("aaa222");
            driver.findElement(By.xpath("//div[@class=\"za_button\"]")).click();
            TimeUnit.SECONDS.sleep(3);
            WebDriver index = driver.switchTo().frame("SI2_mem_index");
            //第一种方式
            WebDriver body = index.switchTo().frame("body");
            //第二种方式
            WebDriver frame = index.switchTo().frame(0);
            //第三种方式
            WebElement iframe = index.findElement(By.tagName("iframe"));
            index.switchTo().frame(iframe);

        } catch (Exception e) {
            webDriver.quit();
            e.printStackTrace();
        }

图片说明

org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
  (Session info: chrome=75.0.3770.100)
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'
System info: host: 'DESKTOP-DP6GTVA', ip: '192.168.18.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.90 (a6dcaf7e3ec6f..., userDataDir: C:\Users\admin\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:52747}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 437da2bca20d8f3601e3eee6bb3f9205
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-09-02 10:42
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)