TA的每日心情 | 奋斗 2017-9-4 10:27 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
想爬取qq空间里面的说说,需要先登录。可是qq空间登录页面有一个iframe,这个框架是有id和name的,当使用id或name定位时,还是报错。
QQ空间登录页面的ifame信息:
<iframe id="login_frame" name="login_frame" scrolling="no" src="https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=https%3A//z.qzone.com/download.html&self_regurl=https%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=https%3A//z.qzone.com/download.html&pt_no_auth=0" height="100%" frameborder="0" width="100%"></iframe>
代码如下:
public class GetContext {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", ".\tools\chromedriver.exe");
WebDriver wb = new ChromeDriver();
wb.get("https://www.baidu.com");
Thread.sleep(2000);
WebElement we = wb.findElement(By.id("kw"));
WebElement we1 = wb.findElement(By.id("su"));
we.sendKeys("QQ空间");
we1.click();
Thread.sleep(2000);
WebElement we2 = wb.findElement(By.id("content_left"));
we2.findElement(By.partialLinkText("留住感动")).click();
Thread.sleep(2000);
wb.switchTo().defaultContent();
WebElement we3 = wb.switchTo().frame("login_frame").findElement(By.id("switcher_plogin"));
Thread.sleep(2000);
可还是报错,报错信息:Exception in thread "main" org.openqa.selenium.NoSuchFrameException: No frame element found by name or id login_frame
请问是什么原因呢? |
|