![](/img/trans.png)
[英]How to check if Xpath exist and get span text in Selenium with Python
[英]Python selenium check if span img exist on the page
我想用 selenium 检查该图像是否存在于页面上。 我尝试了不同的方法,但每次我得到一个错误。 喜欢:
from matplotlib.pyplot import text
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium import webdriver
import time
sosyalkutu=[]
def sosyalkontrol(text):
if sosyalkutu.__contains__(str(text))==True:
return False
else:
sosyalkutu.append(text)
return True
username="hakkibulut"
op=Options()
op.add_experimental_option("debuggerAddress","localhost:8989")
driver= webdriver.Chrome(executable_path="C:\Python\\fiverr\\tiktoklive\\chromedriver.exe",chrome_options=op)
driver.get("http://tiktok.com/@"+username+"/live")
time.sleep(5)
while True:
for socialmess in driver.find_elements(By.XPATH,('//span[@src="https://p16-webcast.tiktokcdn.com/img/maliva/webcast-va/802a21ae29f9fae5abe3693de9f874bd~tplv-obj.png"]')):
print(socialmess.text)
但我收到“不是有效的 XPath 表达式”错误
在此代码行中
for socialmess in driver.find_elements(By.XPATH,('//span[@src="https://p16-webcast.tiktokcdn.com/img/maliva/webcast-va/802a21ae29f9fae5abe3693de9f874bd~tplv-obj.png"]')):
您正在使用多余的括号。
它应该是
for socialmess in driver.find_elements(By.XPATH,'//span[@src="https://p16-webcast.tiktokcdn.com/img/maliva/webcast-va/802a21ae29f9fae5abe3693de9f874bd~tplv-obj.png"]'):
那里。
此外,我不完全确定您使用的是正确的定位器。 我在该页面上找不到与该定位器匹配的任何元素。 不在其他类似页面上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.