python - 使用 selenium 查找站点上其他地方使用的具有多个类的 div。(Python)
问题描述
所以基本上我有这样的东西......
<div class="123">ex1</div>
<div class="456">ex2</div>
<div class="789">ex3</div>
<div class="100">ex4</div>
<div class="123 456 789 100">ex5</div>
<a aria-label="Title" class="the same problem"></a>
我想选择第 5 个 div,而不选择其他 4 个。
我见过一些人这样做:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
driver.findElement(By.cssSelector("div.123.456.789.100"));
但是当我尝试安装 org 模块时,出现“找不到满足 org 要求的版本”错误。
所以我发现了这个:
driver.find_elements_by_xpath("//*[@class='123' or @class='456' or @class='789' or @class='100']")
但我也得到了
"selenium.common.exceptions.NoSuchElementException: 消息:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//*[@class='123' 或 @class='456 ' 或 @class='789' 或 @class='100']"}"
错误。
我已经完成了我的研究,没有任何帮助,所以我决定在这里问。
另外我想稍后从那个“a”对象中获取 aria-label 文本,它有我之前描述的相同问题。我可能会自己弄清楚。现在我真的很想知道如何让它工作。
解决方案
首先,您使用什么语言?通过进口组织。如果我没记错的话是java,那么你使用的是python。
要在 python 中查找元素,只需:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://you_site')
driver.find_element_by_xpath('//div[@class="123 456 789 100"]')
尝试这个,
推荐阅读
- path - 如何让我的寻路算法突出显示最短路径?
- c - 对受限指针的子指针的限制?
- java - 正则表达式获取最后一个值
- node.js - 将 promiseAll 转换为渐进式 promise 解决(例如每 3 个promises)不起作用
- java - 如何在 smooks 中设置语言环境
- ios - NavigationLink 似乎只占用很小的空间
- r - 如何转置特定列值的数据框?
- javascript - javascript AudioNodes不能改变采样率
- python - BeaitifulSoup 无法读取所有命名空间
- gstreamer - GStreamer 'rawvideoparse' 元素读取错误的字节数