| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
小弟第一次发帖,还有点小激动,我尽量把问题描述清楚。。 
 
用selenium模拟登录12306 
 
 
from selenium import webdriver 
  
driver = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe") 
 
driver.set_window_size(1200, 900) 
 
driver.get(’https://kyfw.12306.cn/otn/resources/login.html‘) 
 
 
其实上面这个代码比较简单。 
 
如果网络情况很好,那么跑起来没什么问题; 
 
但是,如果网络状况不好,那么这个网页一直加载不出来,就会一直不能进行下面的操作。 
 
并且我发现在网页加载的时候,手动点一下浏览器上的刷新按钮就可以刷新网页完成加载,并且下面的代码也会继续跑,所以我想问怎么才能模拟点击这个刷新。 
 
之前在网上搜索说用refresh(),我试过了没有反应,这个refresh跟手动点击是不一样的,有谁知道怎么办吗? 
 
多谢大家!!!
- #方法一:Using sendKeys.Keys method
 
 - driver.get("https://kyfw.12306.cn/otn/resources/login.html");
 
 - driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);
 
  
- #方法二:Using navigate.refresh()  method
 
 - driver.get("https://kyfw.12306.cn/otn/resources/login.html");
 
 - driver.navigate().refresh();
 
  
 
- #方法三:Using navigate.to() method
 
 - driver.get("https://kyfw.12306.cn/otn/resources/login.html");
 
 - driver.navigate().to(driver.getCurrentUrl());
 
  
 
- #方法四:Using get() method
 
 - driver.get("https://kyfw.12306.cn/otn/resources/login.html");
 
 - driver.get(driver.getCurrentUrl());
 
  
- #方法五:Using sendKeys() method
 
 - driver.get("https://kyfw.12306.cn/otn/resources/login.html");
 
 - driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");
 
  复制代码 
 
 
 |   
 
 
 
 |