2017-03-03 6 views
0
  1. 0から415までは
  2. 416から550が動作するように私のXPATHロケータが突然動作を停止したのはなぜですか?

  3. 次のロケータの使用に失敗した合格したビルド:

    public @FindBy(xpath = ".//*[@id='menu']/ul//a[@href='/driving-experiences']") WebElement link_DrivingExperiences; 
    
  4. 今、突然、それは動作を停止しましたが、私が使って試してみました絶対XPATHとそれは動作します。私は避けようとしていますが、私は動的ロケータを使用しようとしています。

  5. 私のクリック方法:

    public void waitAndClickElement(WebElement element) throws InterruptedException { 
    boolean clicked = false; 
    int attempts = 0; 
    while (!clicked && attempts < 3) { 
        try { 
         this.wait.until(ExpectedConditions.elementToBeClickable(element)).click(); 
         System.out.println("Successfully clicked on the WebElement: " + "<" + element.toString() + ">"); 
         clicked = true; 
        } catch (Exception e) { 
         System.out.println("Unable to wait and click on WebElement, Exception: " + e.getMessage()); 
         Assert.fail("Unable to wait and click on the WebElement, using locator: " + "<" + element.toString() + ">"); 
        } 
        attempts++; 
    } 
    

    }

  6. HTML要素: enter image description here

+1

「停止しました」とはどういう意味ですか?今は 'NoSuchElementException'を出しているのですか?私はXPathを避け、代わりにCssSelectorを使用しようとしています。一度通常は短い方法で要素を見つけることができますが、DOMの変更によってCssSelectorで簡単にテストが中断されることはありません。 – Tom

+1

提供されている 'HTML'を考えると、' XPath'は大丈夫です。例外ログを共有する – Andersson

+0

画像の代わりにテキストとしてHTMLを投稿してください。潜在的な回答者が使いやすく読めるようにします。 By.linkText( "Driving") 'や' By.cssSelector( "a [href = '/ driving-experiences']") 'のような単純なものを試しましたか?あまりにも深く入れ子になっているXPathの効果が見られます。前後のHTMLなどがなくては言い難い – JeffC

答えて

0

のようなものを試してみてください...

public @FindBy(xpath = "//a[contains(@class, 'toplevellink') and contains(@href, 'driving-experiences')]"))

乾杯、

1
あなたのケースで「運転」リンクテキストが含まれている場合は、おそらく長期的に

//a[text()='Driving'] or 
//a[contains(text(),'Driving')] 

ユースケース2に変更されることはありませんリンクテキストのために行くことができ

先頭または末尾の空白。

関連する問題