簡體   English   中英

Selenium 和 Java:在元素中查找元素

[英]Selenium and Java: Finding elements within elements

我在讓 Selenium 在其他幾個元素中通過它的類找到一個按鈕時遇到了一些麻煩,最上面的元素有一個id

標記:

<li>
 <input data-e2e-selector="beslotningsstotte-ja" class="hb-radiobutton id="beslutningsstotte-0-0" value="NEI">
  <div class="hb-label>
   <label class="hb-label-tekst" id="beslutningsstotte-0-0-NEI-label" for="beslutningsstotte-0-0"> Nei 
    <hb-hjelpetekst>
     <div class="hb-hjelpetekst">
      <button type="button" class="hb-hjelpetekst-knapp">
       <span id="bd9e3ac7-d2cb-45ee-8f2a-e2a57cec87a1-hjelptekst-knapp"><span translate="">Åpne hjelpetekst</span></span>
        <hb-ikon ikonid="hb-question-mark" storrelse="" id="hb-question-mark-60b067d7-978d-4a6f-ac66-e2ec402e5b78" class="hb-ikon hb-ikon-- hb-ikon--hb-question-mark">
         <svg focusable="false"><use xlink:href="assets/sprite.symbol.svg#ikon-hb-question-mark"></use></svg>
        </hb-ikon>
      </button><div _ngcontent-mep-c50="" role="tooltip" aria-hidden="false" aria-live="polite" class="hb-hjelpetekst-innhold hb-hjelpetekst--utvidet-ontop"><div _ngcontent-mep-c50=""

我試圖訪問的元素是<button type="button" class="hb-hjelpetekst-knapp"> ,它有一個不能使用的動態ID

所以,我想試試ByChained()

this.element.findElement(new ByChained(By.id("beslutningsstotte-0-0"), By.className("hb-hjelpetekst-knapp"))).click();

但這給出了這個錯誤:

org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.chained({By.id: beslutningsstotte-0-0,By.className: hb-hjelpetekst-knapp})

我的ByChained()規范是問題嗎?

我還嘗試將所有元素鏈接到元素:

this.element.findElement(new ByChained(By.id("beslutningsstotte-0-0"), By.className("hb-label"), By.className("hb-label-tekst"),
        By.tagName("hb-hjelpetekst"), By.className("hb-hjelpetekst"), By.className("hb-hjelpetekst-knapp"))).click();

這也沒有幫助。

想法?

你能把這個:

this.element.findElement(By.cssSelector("input[type='button'][value='Open device access']")).click();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM