gpt4 book ai didi

java - 通过 Java 中具有动态 ID 的表查找 selenium 脚本的值

转载 作者:太空宇宙 更新时间:2023-11-04 12:49:26 25 4
gpt4 key购买 nike

下面是页面的源代码,我想从下面搜索名称为“Dropbox”的元素。 ID 是随机 ID,因此无法使用它进行搜索。

<div class="main-container">
<div class="navbar-content">
<div class="main-content">
<div id="dnsrp3wdegf881" class="container" style="height: 564px;">
<div class="row">
<div class="row">
<div class="col-md-12" style="padding:0">
<div class="panel panel-default" style="border:none; margin-bottom: 0;">
<div class="panel-body messages">
<div id="records-section" style="display: block; float: left; position: static;" rel="sections">
<ul class="messages-list">
<li id="3nsprserf" class="messages-search thegrey">
<li id="3nsprserfcnf55" class="messages-search thegrey" style="border-bottom:none; padding-top:0; padding-bottom:0">
<li>
<li class="messages-search" style="padding: 10px 0; padding-top:0; padding-bottom:0">
<div id="maintblcnts3cdr3" class="panel-scroll ps-container" style="height: 435px;">
<div id="preloadongo" style="width: 100%; height: 100%; position: absolute; left: 0px; top: 0px; display: none;"></div>
<div id="tblContents_wrapper" class="dataTables_wrapper form-inline" role="grid">
<div class=""></div>
<table id="tblContents" class="table table-hover table-full-width dataTable" aria-describedby="tblContents_info">
<tbody id="table_body" role="alert" aria-live="polite" aria-relevant="all">
<tr id="4FDF448C566E5977" class="odd" style="opacity: 1;">
<tr id="7F5AA7C9566E5977" class="even markrow">
<tr id="3CD258A7566E5977" class="odd">
<tr id="E1DE54EE566E5977" class="even">
<tr id="DCDFD780566E5977" class="odd">
<tr id="1FE7B06E566E5856" class="even">
<tr id="8D10800C566E5856" class="odd">
<tr id="5B1A3BAC566E5977" class="even">
<tr id="2B2A9F30566E5856" class="odd">
<tr id="6A6FDCCD566E5977" class="even">
<tr id="B0EAABBB566E5977" class="odd">
<td class="">
<td id="B0EAABBB566E5977" class="">
<td id="B0EAABBB566E5977" class="main-record">
<b>Dropbox</b> //Have to search and click on this element
<span>splashdrop</span>
</td>
</tr>
<td>

Source code

最佳答案

尝试使用 contains 文本的 xpath:

driver.findElement(By.xpath("//*[contains(text(), 'Dropbox')]"))

关于java - 通过 Java 中具有动态 ID 的表查找 selenium 脚本的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35984097/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com