To compare selenium xpath values

随声附和 提交于 2021-02-11 13:50:21

问题


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.


回答1:


Here's an XPath example to select/click on something without comment. This website seems to use the same system as your sample data :

http://cineaste.co.kr/

To select the entries with no comment for the movies block ("영화이야기"), just use :

//h3[.="영화이야기"]/following::div[@class="widget-small-box"][1]//li[@class="ellipsis"][not(contains(.,"+"))]

We verify the presence of the "+" in the li node to filter the data.




回答2:


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.



来源:https://stackoverflow.com/questions/61882222/to-compare-selenium-xpath-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!