如何使用webdriver等我们不知道下一页(对象)

时间:2016-01-25 15:38:56

标签: selenium selenium-webdriver

第1步:转到网址:https://www.charter.com/buyflow/buyflow-localization

步骤2:输入地址,然后单击继续按钮。

streetAddress   zipCode
9798 hale dr    63123
1101 Toole Av   59802
1205 Toole Av, apt 3    59802
1098 Mosaic Dr. 76179

第3步:我们不知道下一页会是什么,它可能是以下之一

a.  https://www.charter.com/buyflow/multiple-addresses
b.  https://www.charter.com/buyflow/localization-error
c.  https://www.charter.com/buyflow/address-does-not-match
d.  https://www.charter.com/buyflow/address-clarification
e.  https://www.charter.com/buyflow/retrieve-cart-implicit/
f.  https://www.charter.com/buyflow/store-front

所以在步骤2之后,我必须等待下一页加载。目前我正在使用thread.sleep();但每次我必须等待特定的时间,虽然页面加载。 所以我想在这里说一些流利的等待。 那我怎么能这样做呢?

请帮忙

3 个答案:

答案 0 :(得分:0)

在您的情况下,等待加载面板的隐身,听起来合乎逻辑依赖:

<div ng-show="loadingPanel.show" class="loading-panel row ng-hide"> 
 <div class="col-md-4 col-md-offset-4"> 
  <img class="large-logo center-block" src="/resources/images/residential/logo-charter.png" alt="loading"> 
  <p class="text-center">LOADING</p> 
  <img class="timer center-block" src="/resources/images/residential/buyflow/loading-time.gif" alt="Charter Spectrum Loading Timer"> 
 </div> 
</div>

Python中的示例:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 10).until(
    EC.invisibility_of_element_located((By.CSS_SELECTOR, ".loading-panel"))
)

答案 1 :(得分:0)

正如我所观察到的,你总是得到图标LiveChat(在页面加载完毕后),无论下一页是什么,所以我会用Java做到这一点:

webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("rnowChatLink_type1")));

使用网站上的ID

答案 2 :(得分:0)

同意Alecxe。

在java中,试试这个:

WebDriverWait wait = new WebDriverWait(driver, 30);//driver is webdriver
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".panel.panel-primary.panel-unstyled-sm")));