比较 selenium xpath 值 [英] To compare selenium xpath values

查看:27
本文介绍了比较 selenium xpath 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您正在尝试通过比较 xpath 值来运行它们.你想比较一下有没有评论.

如果有评论,生成span class="full-right count or changed".如果你没有它,它就不会被生产出来.

<代码>xpath 注释//*[@id="thema_wrapper"]/div[3]/div/div/div[3]/div/div[7]/div[2]/div[1]/div[2]/一个/跨度

xpath nocomment//*[@id="thema_wrapper"]/div[3]/div/div/div[3]/div/div[7]/div[2]/div[1]/div[2]/一/

我认为我们可以将其与 if,else 进行比较,但我不知道如何进行.<代码>如果#nocomment 开始别的#评论停止我搜索了很多数据,但找不到.请帮帮我.

哦,是同一个系统.我测试了一下,有错误.

<预>selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{"method":"xpath","selector":"//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]"}(会话信息:chrome=81.0.4044.138)

from selenium import webdriver导入时间路径 = "C:\chromed\chromedriver.exe"驱动程序 = webdriver.Chrome(path) #path''''''driver.get("http://cineaste.co.kr/") #url时间.睡眠(0.5)postclick = driver.find_element_by_xpath("//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]") #로그인창 활성화点击后点击()驱动程序关闭()

你能举个例子吗?我想忽略有评论的帖子,点击没有评论的帖子.

You are trying to run xpath values by comparing them. You want to compare whether there are comments or not.

<div class="media-body">
			<a href="https://url" class="ellipsis">
									<span class="pull-right count orangered">
						&nbsp;+26					</span>
												post title			</a>
			<div class="media-info ellipsis">
				admin				<i class="fa fa-clock-o"></i> date			</div>
		</div>

If there is a comment, span class="full-right count or changed" is generated. If you don't have it, it won't be produced.

xpath comment //*[@id="thema_wrapper"]/div[3]/div/div/div[3]/div/div[7]/div[2]/div[1]/div[2]/a/span

xpath nocomment //*[@id="thema_wrapper"]/div[3]/div/div/div[3]/div/div[7]/div[2]/div[1]/div[2]/a/

I think we can compare this with if,else,but I don't know how. if #nocomment start else #comment stop I searched a lot for the data, but I couldn't find it. Please help me.

解决方案

Oh, it's the same system. I tested it and there was an error.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]"}
  (Session info: chrome=81.0.4044.138)

from selenium import webdriver
import time

path = "C:\chromed\chromedriver.exe"
driver = webdriver.Chrome(path) #path
'''

'''
driver.get("http://cineaste.co.kr/") #url
time.sleep(0.5)

postclick = driver.find_element_by_xpath("//h3[.='영화이야기']/following::div[@class='widget-small-box'][1]//li[@class='ellipsis'][not(contains(.,'+'))]") #로그인창 활성화
postclick.click()


driver.close()

Could you make an example with the site? I want to ignore the posts with comments and just click the ones without comments.

这篇关于比较 selenium xpath 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆