2016-08-22 178 views
0

位於元素的存在我的下面的代碼工作正常,但現在,我得到超時響應。我不確定如何處理這個超時問題 - 請告知。超時30秒後,等待

public void Browse_Samsung() throws Exception 
    { 
     WebDriverWait wait = new WebDriverWait(driver, 30); 
     Actions act = new Actions(driver); 
     act.moveToElement(Digital_Menu).perform(); 
     act.click(wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='CategoryMenu1']//a[@title='Samsung']")))).build().perform(); 

     WebElement Micromax = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='filter_1Option_21']//a[@title='GSM Mobile Phones - Micromax']"))); 

     JavascriptExecutor js = (JavascriptExecutor)driver; 
     js.executeScript("arguments[0].scrollIntoView(true);arguments[0].click()", Micromax); 

    } 
} 

場景:

  1. 登錄www.homeshop18.com
  2. 從左邊 顯示在 「品牌」 一節 「數字」 菜單現在
  3. 選擇 「三星」我需要SCROLL並選擇另一個名爲「Micromax」的品牌。

Error: org.openqa.selenium.TimeoutException: Timed out after 30 seconds waiting for presence of element located by: By.xpath: //*[@id='filter_1Option_21']//a[@title='GSM Mobile Phones - Micromax']

+0

檢查單擊如果所有的定位器仍然有效。 – Guy

回答

0

試試這個,這是完全工作我,我很能上「福邦」

Actions action = new Actions(driver); 

action.moveToElement(driver.findElement(By.linkText("Digital"))).build().perform(); 

WebDriverWait wait = new WebDriverWait(driver,30); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Samsung"))); 

driver.findElement(By.linkText("Samsung")).click(); 

driver.findElement(By.xpath("//input[@class='input inputBox_filter_Brand']")).sendKeys("Micromax"); 

WebDriverWait wait1= new WebDriverWait(driver,30); 

wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@title='GSM Mobile Phones - Micromax']"))); 

driver.findElement(By.xpath("//a[@title='GSM Mobile Phones - Micromax']")).click(); 
1

你有錯的ID在你的XPath:

//*[@id='filter_1Option_21']//a[@title='GSM Mobile Phones - Micromax'] 

您應該使用filter_1Option_20但更好的使用XPath的:

//li/a[@title='GSM Mobile Phones - Micromax'] 

我覺得你的過濾器ID不是常數所以最好不要在xpath中使用ID。