PhantomJsDriver在网站上捕获错误

时间:2016-11-28 05:51:44

标签: java selenium phantomjs

我使用了phantomjs版本2.x和PhantomJsDriver 1.3.0。

我的代码在这里。

String cli_args[] = new String[]{
"--web-security=false",
"--ssl-protocol=any",
"--ignore-ssl-errors=true",
"--webdriver-loglevel=DEBUG"
};

DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("takesScreenshot", true);
capabilities.setCapability("userAgent", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/1A542a Safari/419.3");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cli_args);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "/usr/local/bin/phantomjs");

PhantomJSDriver driver = new PhantomJSDriver(capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS).pageLoadTimeout(20, TimeUnit.SECONDS).setScriptTimeout(15, TimeUnit.SECONDS);

driver.get("https://m.naver.com");

driver.findElement(By.xpath("//div[@id=\"nav\"]/div[3]/nav/ul/li[1]/a")).click();

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id="nmap_news_1"]/a")));

------- NOT Found: GAVE UP. error

new WebDriverWait(driver, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id="nmap_news_1"]/a/span/img")));

------- NOT Found: GAVE UP. error

WebElement creativeElem = driver.findElement(By.xpath("//div[@id="nmap_news_1"]/a"));

------- NOT Found: GAVE UP. error

和phantomjs错误消息 - >

  1. ReferenceError:无法找到变量:音频

  2. TypeError:undefined不是对象(评估' e.srcElement.tagName.toUpperCase')

  3. TypeError:undefined不是对象(评估' naver.main.myteam.init')

  4. 我需要得到这个元素。

    <div id="nmap_news_1" class="ad" data-unit="1120D" data-tb="NEWS_1" data-extra="" data-mdom-unit="1120H" data-mdom="true" data-dom-url="http://mv.ad.naver.com/adshow" data-da-revision="161128111917755" data-position-type="rel" data-position-index="0" data-position-computed-index="7"><a href="https://mv.ad.naver.com/adclick?unit=1120D&amp;ac=7295638&amp;src=2984824&amp;br=2377222&amp;tb=NEWS_1&amp;rk=WDvKYQpjaWgAADt1PpUAAAFd&amp;eltts=oUooYL2N5fMvr1oK0dRHnw%3D%3D&amp;x_dy=828&amp;x_ih=521&amp;x_th=85&amp;x_iv=0" style="display:block;background:#fff;text-decoration:none;"><span id="nbp_da_img" style="display:block;width:100%;height:85px;background:url(https://ssl.pstatic.net/tveta/libs/1143/1143047/20161101160143-ebDDLUF3_bg_left.jpg) repeat-x;background-size:auto 85px;-webkit-background-size:1px 85px;text-decoration:none;text-align:center;font-size:0;"><img src="https://ssl.pstatic.net/tveta/libs/1143/1143047/20161101160143-ebDDLUF3.jpg" alt="AD" width="320" height="85" data-media-width="640" data-media-height="170" data-content-type="image" data-bakery="material" style="vertical-align:top;border:none" onload="naver_corp_da.logParamManager['nmap_news_1'].imgOnloadHandler();">&nbsp;</span></a></div>
    

    我的代码获取元素在这里:

    <div id="nmap_news_1" class="ad ready" data-unit="1120D" data-tb="NEWS_1" data-extra="" data-mdom-unit="1120H" data-mdom="true" data-dom-url="http://mv.ad.naver.com/adshow" data-da-revision="161128111917755" data-position-type="rel" data-position-index="0" data-position-computed-index="7">
    <span class="ad_load">
    </span>
    </div>
    

    任何人都知道为什么会这样吗?

0 个答案:

没有答案