Roboframework-Selenium-查找包含特定文本的所有HREF
我的目标是在包含特定文本的网页中查找所有HREF链接。 使用我在“查找元素”中测试的Chrome开发工具: 它的工作原理非常好,因为它返回了所有的数据 当我尝试将其包含在robotframework脚本中时:Roboframework-Selenium-查找包含特定文本的所有HREF,selenium,xpath,selenium-chromedriver,robotframework,Selenium,Xpath,Selenium Chromedriver,Robotframework,我的目标是在包含特定文本的网页中查找所有HREF链接。 使用我在“查找元素”中测试的Chrome开发工具: 它的工作原理非常好,因为它返回了所有的数据 当我尝试将其包含在robotframework脚本中时: ${elements}= Get WebElements xpath://[href*='photo/?fbid'] FOR ${element} IN @{elements} Log ${element.text}
${elements}= Get WebElements xpath://[href*='photo/?fbid']
FOR ${element} IN @{elements}
Log ${element.text}
Log ${element}
END
我获得错误消息:
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression //[href*='photo/?fbid'] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[href*='photo/?fbid']' is not a valid XPath expression.
(Session info: chrome=86.0.4240.111)
我试图查看文档,但不明白什么是正确的语法。
感谢您的帮助。
谢谢问题是您混合了xpath和CSS。使用的选择器是CSS选择器,然后将其作为XPATH传递。所以你可以用两种方法来做 XPATH
Get WebElements xpath://a[contains(@href,'photo/?fbid')]
CSS
Get WebElements css:a[href*='photo/?fbid']
谢谢,当我得到所有元素时,我得到了字符串=>${element}=。您知道所有Get WebElements如何获取实际的HTTP链接吗?这是因为您打印了元素而不是打印其href属性。看看
Get WebElements css:a[href*='photo/?fbid']