在Selenium Python中通过XPath模式查找元素 [英] Finding elements by xpath pattern in Selenium python

查看:114
本文介绍了在Selenium Python中通过XPath模式查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用硒python和生菜来测试Django应用程序.

I am working with selenium python and lettuce to test django application.

在以下模式中有很多具有xpath的元素,我不知道文档中存在多少个这些元素.

There are many elements having xpath in the following pattern and i don't know how many of these elements exists in the document.

.//*[@id='accordion-note-1']
.//*[@id='accordion-note-2']
.//*[@id='accordion-note-3']
.//*[@id='accordion-note-4']

是否可以在 driver.find_elements_by_xpath 中使用模式?
基本上,我的目的是使所有具有这种xpath模式的项目.

Is there any way to use pattern in driver.find_elements_by_xpath ?
Basically my purpose is to get all items having this pattern of xpath.

推荐答案

不确定是否可以,但是您可以尝试使用以下xpath:

Not sure this will work, but you can try by using the below xpath:

.//*[starts-with(@id, 'accordion-note')]

这是链接 http://www.zvon.org/xxl/XSLTreference/Output/function_starts -with.html

u也可以在此处使用包含

u can also use contain here like

.//*[contains(@id, 'accordion-note')]     

这篇关于在Selenium Python中通过XPath模式查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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