简体   繁体   English

find_elements_by_partial_link_text(link_text)硒Python

[英]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.

相关问题 Python Selenium从find_elements_by_partial_link_text中提取href信息 - Python Selenium pull href info out of find_elements_by_partial_link_text find_elements_by_partial_link_text将找不到元素 - find_elements_by_partial_link_text won't locate the elements find_element() with Link_Text 无法使用 Selenium Python - find_element() with Link_Text not working using Selenium Python Selenium / python-无法找到部分链接文本 - Selenium/python - fails to find partial link text Selenium/python - “查找部分链接文本”和“xpath” - Selenium/python - “find partial link text ” and “xpath” Selenium Python查找元素部分链接文本 - Selenium Python find element partial link text Selenium 使用 LINK_TEXT 方法在页面上找不到登录按钮 - Selenium unable to find Log In button on the page using LINK_TEXT method “TypeError: 'str' object is not callable” 使用 WebDriverWait 处理 Selenium 到 Python 中的 link_text - “TypeError: 'str' object is not callable” using WebDriverWait for link_text in Selenium through Python 在python硒Webdriver中将link_text与显式等待一起使用时发生TimeOutException - TimeOutException when use link_text with explicit wait in selenium webdriver with python selenium (python) 引发 StaleElementReferenceException 并且不会继续下载所有 webdriver.find_elements_by_partial_link_text() - selenium (python) raises StaleElementReferenceException and does not continue to download all webdriver.find_elements_by_partial_link_text()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM