2017-10-17 76 views
0

我使用自動化網絡硒驅動程序的頁面。我點擊一個元素。在控制檯中不會引發錯誤。元素正在被點擊,但在頁面上沒有可見的影響。我嘗試了很多其他元素,但面臨同樣的問題。每個元素都顯示爲點擊,但沒有影響。點擊動作,但不影響顯示在頁面中硒

示例方案。我是通過單擊元素上的星形圖標來爲元素添加書籤的。點擊時,星星應該變成藍色。當執行的控制檯顯示元素被書籤時,即點擊星號。但在頁面上,該部分不會變成藍色。但它刷新頁面,明星是藍色的。

請幫助我的人可能是什麼問題?

// Method to add a part to bookmarks on results panel 
public void addPartToBookmarksOnResultsPanel(String partName) 
     throws OnePartException { 
    helper = new HelperClass(driver); 
    String trimmedPartName = partName.trim(); 
    // get the count of search results 
    int resultsCount = helper.getResultsCount(); 
    boolean matchFound = false; 
    // get all the search results and iterate through them to find the 
    // required part to be bookmarked. 
    for (int i = 1; i <= resultsCount; i++) { 
     // Get the name of the part to be bookmarked 
     String part = driver 
       .findElement(
         By.xpath("//div[@class='widgetContent']//div[" + i 
           + "]//div//div[2]//div//h3//a")).getText() 
       .trim(); 
     // if obtained part name is same as expected part name, then 
     // click 
     // corresponding part's bookmark icon. 
     if (part.equalsIgnoreCase(trimmedPartName)) { 
      matchFound = true; 
      // Check whether the part is already bookmarked or not 
      String bookmarkStatus = driver.findElement(
        By.xpath("//div[@id='resultList']/div/div[" + i 
          + "]/div/div[2]/div/div/div[2]/span")) 
        .getAttribute("class"); 
      // If already bookmarked, then show the message 
      if (bookmarkStatus.equalsIgnoreCase("addToBasket active")) { 
       logger.info("Part" + trimmedPartName 
         + "is already bookmarked"); 
      } else { 
       click(driver.findElement(By 
         .xpath("//div[@id='resultList']/div/div[" + i 
           + "]/div/div[2]/div/div/div[2]/span/span"))); 
       // Check whether notification is displayed 
       String bookmarkSuccessNotofication = helper 
         .getNotificationMessage(); 
       logger.info("part " 
         + partName 
         + " is suucessfully bookmarked and notification reads " 
         + bookmarkSuccessNotofication); 
       // Thread.sleep(6000); 
      } 
      break; 
     } 
    } 
    // If part is not found in the results, throw an error 
    if (!matchFound) { 
     logger.error("Part " + partName 
       + " is not found in the Results. Error in bookmarking it"); 
     throw new OnePartException("Part " + partName 
       + " is not found in the Results. Error in bookmarking it"); 
    } 
} 
+0

請粘貼代碼 –

+0

我覺得沒有必要的代碼。這是簡單的點擊工作,但不影響頁面。沒有代碼的 –

+0

沒人能幫忙嗎?我們能想象你的問題,但沒有代碼 –

回答

0

我認爲問題是在你的XPath

click(driver.findElement(By 
         .xpath("//div[@id='resultList']/div/div[" + i 
           + "]/div/div[2]/div/div/div[2]/span/span"))); 

這不是一個很好的標準在XPath使用DIV/DIV/DIV或跨度/跨度這麼多次。 當你通過firepath你可能會發現該元素檢查它。但它有可能破裂的可能性非常高。而且你不能在控制檯消息上中繼,因爲你在if塊中給了console.log消息。

嘗試用像個家按鈕,有一個堅實的選擇一些基本的元素,如果它不工作,請與傳統的點擊method.It嘗試可能是一個問題與您的包裝

即driver.findElement(By.xpath (「」))。click();

+0

這是否解決了您的問題? –

相關問題