久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何使用 Selenium 和 Java 提取表格元素的 id 屬性的

How to extract the dynamic values of the id attributes of the table elements using Selenium and Java(如何使用 Selenium 和 Java 提取表格元素的 id 屬性的動態(tài)值)
本文介紹了如何使用 Selenium 和 Java 提取表格元素的 id 屬性的動態(tài)值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個表格,其中每一行都有一個下載鏈接,其中包含(部分)自動生成的 id 元素.這樣做的原因是實(shí)際的 href 元素總是#",所以 id 將下載分開.

I have a table where each row will have a download link with a (partly) auto-generated id element. The reason for this is that the actual href-element will allways be "#", so the id's separate the downloads.

我需要在 td.id 中找到該 id 元素的名稱.即:我知道表格行有一個id元素,而且我知道部分名稱,我需要得到確切的名稱.

I need to find the name of that id element in the td. That is: I know the table row has an id element, and I know part of the name, and I need to get the exact name.

我一次訪問每一行,所以我一次只需要查看一個 td.無需查看整個表格.

I'm accessing each row one at a time, so I only need to look within ONE td at a time. No need to look through the whole table.

當(dāng)我知道名稱時,我就知道如何找到一個元素.但是在只知道類型的情況下找到元素是另一回事.

I know well how to find an element when I know the name. But to find the element when I only know the type is another thing.

...
<tr>
 <td class="journalTable-journalPost"
  <a class="htext-small" href="#" id="downloadJournalPost-345">Download</a>
 </td>
</tr>
<tr>
 <td class="journalTable-journalPost"
  <a class="htext-small" href="#" id="downloadJournalPost-346">Download</a>
 </td>
</tr>
...

我在 webdriver 中找不到任何可以讓我按類型查找元素的方法.

I cannot find any method(s) in the webdriver that lets me find an element by type.

部分名稱會起作用,因?yàn)?id 的名稱為downloadJournalPost-xxx",其中只有 xxx 發(fā)生變化.但是鏈接文本是我能找到的唯一值,它可以讓我搜索部分匹配.

Partial name would work, since the id's get the name "downloadJournalPost-xxx", where only xxx changes. But link text is the only value I can find which lets me search for a partial match.

更完整的標(biāo)記.

<td class="journalTable-journalpost">
 <span class="hb-tekst--sekundar">In <!----><est-ikon class="ng-star-inserted">
  <div aria-hidden="true" class="hb-ikon hb-ikon--pil3-inn  ">
   <svg focusable="false">
    <use xlink:href="#ikon-pil3-inn"></use>
   </svg>
  </div></est-ikon><!----></span>
 <span class="hb-tekst--mellomTittel hb-avstandIngen"> Application and attachments</span>
 <a class="hb-tekst--liten" href="#" id="lastNedJournalPost-2892">Download journal post</a>
</td>

推薦答案

打印你需要的元素的id attributeListvisibilityOfAllElementsLocatedBy() 誘導(dǎo) WebDriverWait 并且您可以使用 Java8 stream()map() 并且您可以使用關(guān)注定位器策略:

To print the List of id attribute of the element you need to induce WebDriverWait for the visibilityOfAllElementsLocatedBy() and you can use Java8 stream() and map() and you can use either of the following Locator Strategies:

  • cssSelector:

List<String> myID = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("td.journalTable-journalPost>a.htext-small"))).stream().map(element->element.getAttribute("id")).collect(Collectors.toList());
System.out.println(myIDs);

  • xpath:

    List<String> myIDs = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("http://td[@class='journalTable-journalPost']/a[@class='htext-small' and text()='Download']"))).stream().map(element->element.getAttribute("id")).collect(Collectors.toList());
    System.out.println(myIDs);
    

  • 這篇關(guān)于如何使用 Selenium 和 Java 提取表格元素的 id 屬性的動態(tài)值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

    【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

    相關(guān)文檔推薦

    How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
    MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
    Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
    Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
    Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
    Use threading to process file chunk by chunk(使用線程逐塊處理文件)
    主站蜘蛛池模板: 国产精品99久久久久久动医院 | 久草院线 | 91社区视频| 91精品国产自产精品男人的天堂 | 精品欧美一区二区精品久久久 | av免费网站在线 | 午夜视频在线 | 亚洲成人网在线 | 欧美a∨ | 欧美一区二区三区 | 亚洲免费观看视频网站 | 国产成人黄色 | av在线免费观看网址 | 国产精品久久精品 | 亚洲国产精品成人无久久精品 | 久久99精品久久久久久狂牛 | 国产精品久久久久久久久久不蜜臀 | 日本二区 | 欧美精品一区二区三区在线播放 | 极品销魂美女一区二区 | 日本午夜免费福利视频 | 国产精品免费一区二区 | 视频二区在线观看 | 亚洲视频中文字幕 | 日韩免费网 | 亚洲永久免费观看 | 日韩欧美国产一区二区三区 | 亚洲一区 | 粉嫩高清一区二区三区 | 岛国av免费观看 | 亚洲 欧美 日韩 在线 | 日韩免费一区二区 | www亚洲精品| 国产精品欧美一区二区三区 | 亚洲精品久久久久久宅男 | 欧美日高清 | www.日本三级 | 亚洲视频在线一区 | a欧美 | 久久精品国产一区 | 国产精品久久久久久久久免费桃花 |