我使用了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错误消息 - >
ReferenceError:无法找到变量:音频
TypeError:undefined不是对象(评估' e.srcElement.tagName.toUpperCase')
TypeError:undefined不是对象(评估' naver.main.myteam.init')
我需要得到这个元素。
<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&ac=7295638&src=2984824&br=2377222&tb=NEWS_1&rk=WDvKYQpjaWgAADt1PpUAAAFd&eltts=oUooYL2N5fMvr1oK0dRHnw%3D%3D&x_dy=828&x_ih=521&x_th=85&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();"> </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>
任何人都知道为什么会这样吗?