gpt4 book ai didi

java - 如何在不使用文本的情况下从页面中选择内容?

转载 作者:行者123 更新时间:2023-11-28 10:24:41 28 4
gpt4 key购买 nike

需要了解如何在不使用文本的情况下选择和单击博客标题,因为内容经常更改。

我没有“li”标签,所以我以前做过的一些事情在这种情况下不起作用。任何帮助将不胜感激。

这是我尝试的最后一件事:

driver.findElement(By.xpath("(//h2[contains(@class, 'blog-post-title')])[3]/a")).click();

<!DOCTYPE html>

<html>
<head>
<title></title>
</head>

<body>
<div class="view-content">
<div class="views-row views-row-1">
<span class="pubdate">July 31, 2012</span>

<h2 class="blog-post-title"><a href=
"/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it">The
Surprise Attack (And When Not to Do It)</a></h2>

<p class='field-summary'>With 200 meters remaining in the
250-kilometer Men’s Olympic Road Race last Saturday, Colombia’s
Rigoberto Uran made a fatal mistake: He turned his head to see what
was happening behind him....</p><a class="read-more" href=
"/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it">Read
more</a>

<ul class="links inline">
<li class="datetime first"><span>Posted at <time class=
"timestamp" datetime="2012-07-31T17:41:04-04:00">5:41
PM</time></span></li>

<li class="disqus_comments_num"><a data-disqus-identifier=
"node/28978" href=
"/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it#disqus_thread">
Comments</a></li>

<li class="email"><a class="sharebtn" href=
"mailto:?subject=The%20Surprise%20Attack%20%28And%20When%20Not%20to%20Do%20It%29&amp;amp;body=With%20200%20meters%20remaining%20in%20the%20250-kilometer%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/news/pro-cycling/ahead-pack-vinokourov-sprints-olympic-gold&amp;quot;&amp;gt;Men%E2%80%99s...%20http://stage7.bicycling.com/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it">
</a></li>

<li class="facebook"><a class="sharebtn" href=
"http://www.facebook.com/sharer.php?s=100&amp;p[url]=http://stage7.bicycling.com/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it&amp;p[title]=The%20Surprise%20Attack%20%28And%20When%20Not%20to%20Do%20It%29&amp;p[summary]=With%20200%20meters%20remaining%20in%20the%20250-kilometer%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/news/pro-cycling/ahead-pack-vinokourov-sprints-olympic-gold&amp;quot;&amp;gt;Men%E2%80%99s...">
</a></li>

<li class="twitter"><a class="sharebtn" href=
"https://twitter.com/intent/tweet?text=The%20Surprise%20Attack%20%28And%20When%20Not%20to%20Do%20It%29&amp;url=http://stage7.bicycling.com/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it&amp;via=bicyclingmag">
</a></li>

<li class="pinterest"><a class="sharebtn" href=
"http://pinterest.com/pin/create/button/?url=http://stage7.bicycling.com/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it&amp;description=With%20200%20meters%20remaining%20in%20the%20250-kilometer%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/news/pro-cycling/ahead-pack-vinokourov-sprints-olympic-gold&amp;quot;&amp;gt;Men%E2%80%99s...">
</a></li>

<li class="googleplus last"><a class="sharebtn" href=
"https://plus.google.com/share?url=http://stage7.bicycling.com/blogs/roadscholar/the-surprise-attack-and-when-not-to-do-it">
</a></li>
</ul>
</div>

<div class="views-row views-row-2">
<span class="pubdate">June 20, 2012</span>

<h2 class="blog-post-title"><a href=
"/blogs/roadscholar/advanced-team-construction-capstone-seminar">Advanced
Team Construction (Capstone Seminar)</a></h2>

<p class='field-summary'>At some point this week, a selection panel
consisting of Team Sky managers and coaches will sit down to make a
difficult decision: which nine of the team’s 28 riders will be in
Liege, Belgium, on Saturday, June 30th for the start of the 2012
Tour de France....</p><a class="read-more" href=
"/blogs/roadscholar/advanced-team-construction-capstone-seminar">Read
more</a>

<ul class="links inline">
<li class="datetime first"><span>Posted at <time class=
"timestamp" datetime="2012-06-20T22:01:48-04:00">10:01
PM</time></span></li>

<li class="disqus_comments_num"><a data-disqus-identifier=
"node/28977" href=
"/blogs/roadscholar/advanced-team-construction-capstone-seminar#disqus_thread">
Comments</a></li>

<li class="email"><a class="sharebtn" href=
"mailto:?subject=Advanced%20Team%20Construction%20%28Capstone%20Seminar%29&amp;amp;body=At%20some%20point%20this%20week,%20a%20selection%20panel%20consisting%20of%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/tags/team-sky&amp;quot;&amp;gt;Team...%20http://stage7.bicycling.com/blogs/roadscholar/advanced-team-construction-capstone-seminar">
</a></li>

<li class="facebook"><a class="sharebtn" href=
"http://www.facebook.com/sharer.php?s=100&amp;p[url]=http://stage7.bicycling.com/blogs/roadscholar/advanced-team-construction-capstone-seminar&amp;p[title]=Advanced%20Team%20Construction%20%28Capstone%20Seminar%29&amp;p[summary]=At%20some%20point%20this%20week,%20a%20selection%20panel%20consisting%20of%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/tags/team-sky&amp;quot;&amp;gt;Team...">
</a></li>

<li class="twitter"><a class="sharebtn" href=
"https://twitter.com/intent/tweet?text=Advanced%20Team%20Construction%20%28Capstone%20Seminar%29&amp;url=http://stage7.bicycling.com/blogs/roadscholar/advanced-team-construction-capstone-seminar&amp;via=bicyclingmag">
</a></li>

<li class="pinterest"><a class="sharebtn" href=
"http://pinterest.com/pin/create/button/?url=http://stage7.bicycling.com/blogs/roadscholar/advanced-team-construction-capstone-seminar&amp;description=At%20some%20point%20this%20week,%20a%20selection%20panel%20consisting%20of%20&amp;lt;a%20href=&amp;quot;http://www.bicycling.com/tags/team-sky&amp;quot;&amp;gt;Team...">
</a></li>

<li class="googleplus last"><a class="sharebtn" href=
"https://plus.google.com/share?url=http://stage7.bicycling.com/blogs/roadscholar/advanced-team-construction-capstone-seminar">
</a></li>
</ul>
</div>
</div>
</body>
</html>

最佳答案

Jquery 可以使用标准的 css 样式选择器,例如 class 和 id。例如

// Class
$('.my-class')
// Id
$('#my-id')
// Element
$('div')

点击...

// You don't have to pass event, but it may be useful
$('.my-class').click(function (event) {
/* Do something */
});

希望这对您有所帮助。快速谷歌搜索应该会向您显示更多内容。 :)

关于java - 如何在不使用文本的情况下从页面中选择内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784876/

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