[英]find_elements_by_partial_link_text(link_text) Selenium Python
Got this issue: I'm trying to find the last link on webpage: 遇到了这个问题:我正在尝试找到网页上的最后一个链接:
try:
elems=self.br.find_elements_by_partial_link_text(category)
except NoSuchElementException:
print 'The Category Name Was Not Found'.category
f=open("error.log","aw")
f.write("Cant find category:%s\n"%category)
f.close()
elems[-1].click()
Now for exmaple the categories I have: Books (Dynamic Number) AudioBooks (Dynamic Number) RomanceBooks (Dynamic Number) 现在来看一下我拥有的类别:书籍(动态编号)有声读物(动态编号)RomanceBooks(动态编号)
And I try to find "Books" I want to get the first one! 我试图找到我想要的第一本书! (Also it needs to be the last on the source so can't choose first from the elements) One thing that will work with my system if I was able to choose partial_link_text starting with books and not ending?
(而且它必须是源代码中的最后一个,因此不能从元素中首先选择)如果我能够选择从书本开始而不是书本结尾的partial_link_text,这件事对我的系统有用吗? Any ideas?
有任何想法吗? I can't use any other method because It's a really dynamic code and most of the stuff changes...
我不能使用任何其他方法,因为这是一个真正的动态代码,并且大多数内容都在变化...
You can use something like this 你可以用这样的东西
xpath="//a[starts-with(text(), %s)]" % category
elems = self.br.find_elements_by_xpath(xpath)
elem = elems[-1]
xpath will do the starts-with
part of work, and elems[-1]
will do the rest xpath将
starts-with
工作,部分工作由elems[-1]
完成
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.