2017-10-17 6 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またはスパン/スパン非常に多くの時間を使用するには良い標準ではありませんであると思います。 ファイヤーパスでチェックすると、要素が見つかる可能性があります。しかし、それが壊れる可能性が非常に高いです。そして、あなたがブロックの中にconsole.logメッセージを与えたので、あなたはコンソールメッセージでリレーすることはできません。 By.xpath(

固体セレクタを持ってホームボタンのようないくつかの基本的な要素で試してみて、それが働いていない場合は、あなたのラッパー

すなわちdriver.findElementで問題になる可能性があります伝統的なクリックmethod.Itで試してみてください( ""))をクリックします。

+0

これで問題は解決しましたか? –

関連する問題