【AI问答】

Question 1:在selenium中模糊查找class

Hello, I would like to use selenium to fuzzily search for a class. What can I do?
In class, only ‘abc’ is known

class=‘abc – as8d7asufaskjhfa’

AI- answer:
Hi, thank you for using Bing. Selenium is a popular tool for automating web browser interactions. Fuzzy search is a technique for finding approximate matches for a given query. If you want to use selenium to fuzzily search for a class, you can try some of the following methods:

You can use the By.cssSelector method to find elements that have a class attribute that ends with, starts with, or contains a certain string. For example, if you want to find elements that have a class attribute that ends with ‘abc’, you can use By.cssSelector(“[class$=abc]”). Similarly, you can use By.cssSelector(“[class^=abc]”) for elements that start with ‘abc’, and By.cssSelector(“[class*=abc]”) for elements that contain ‘abc’. You can also combine these selectors with logical operators like and and or. For more details, see this answer1.
You can use the By.xpath method to find elements that have a class attribute that matches a certain XPath expression. XPath is a language for querying XML documents, and it has many functions and operators for finding partial matches. For example, if you want to find elements that have a class attribute that contains ‘abc’, you can use By.xpath(“//[contains(@class,‘abc’)]“). Similarly, you can use By.xpath(”//[starts-with(@class,‘abc’)]”) for elements that start with ‘abc’, and By.xpath(“//*[ends-with(@class,‘abc’)]”) for elements that end with ‘abc’. You can also use other XPath functions like matches, substring, and translate to perform more complex fuzzy matching. For more details, see this answer2.
You can use the driver.findElements method to find all the elements that have a certain class name, and then iterate over them and compare their text or attributes with your query using Python’s built-in string methods or regular expressions. For example, if you want to find elements that have a class name ‘abc’ and their text contains ‘xyz’, you can use something like this:
elements = driver.findElements(By.className(“abc”))
for element in elements:
if “xyz” in element.text:
# do something with the element
Copy
For more details, see this answer.

I hope this helps you with your selenium project. Have a nice day! 😊

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值