2013-10-08 47 views
0

我遇到了一種情況,在選擇組合框值的文本框值改變。我需要等到文本框更改爲特定值。我已經嘗試過了。直到,請幫助我解決這個問題。硒等到文本框值改變

+0

使用內置等待邏輯的Webdriver - ExplicitWait。 http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits – Akbar

+0

您是否嘗試過使用以下邏輯? '公共靜態WebDriverWait webDriverWait = null; webDriverWait = new WebDriverWait(driver,480); \t \t webDriverWait.until(ExpectedConditions.textToBePresentInElement(By.xpath(「textbox xpath」),「您正在等待的文本」)); ' – Hemanth

回答

0

如果您已經知道值將在組合框更改後的文本框中反映出來。然後你可以創建一個xPath。

// * [包含(文本(), 'Expectedvalue']

然後創建檢查XPATH是否可用與否的方法。

public boolean isElementPresent(String xPath)` 
{ 
    try 
    { 
     this.driver.findElement(By.xpath(xPath); 
     return true; 
    } 
     catch() 
     { 
     return false; 
     } 
    } 

然後可以檢查使用while循環

`//Do the code for changing combo box value 
    while(isElementPresent("//*[contains(text(),'Expectedvalue']") 
{//do the necessary actions}` 
0

//假設組合框編輯也文本框可見

while(! driver.findElement(By.xpath("textboxXpath")).getText().equalsIgnoreCase("expected value")) 
{ 
    System.out.println("waiting for text to be loaded"); 
} 

此循環結束時,文本框必須加載期望值 注意: 這可能會導致您無限執行。實施有限制。

0
while(! driver.findElement(By.id("id_of_combo_box")).getAttribute("value").equals("Expected Value")) 
{/*Loops till value is written*/} 

這裏我們循環直到組合框的值等於期望值。