【发布时间】:2021-11-22 00:34:45
【问题描述】:
我目前遇到一种情况,我需要获取页面上的所有元素,逐个遍历元素并在每个元素内,我想查看是否存在某个其他元素。
为了更清楚,这是我的循环:
${elements} = Get WebElements //li[@class='product-item--row js_item_root ']
FOR ${item} IN @{elements}
This is the part where I need to check within ${item} if the xpath exists:
//*[contains(text(), '${companyname}')]
END
所以基本上,我的页面上有 24 个元素具有 xpath
//li[@class='product-item--row js_item_root ']
我的页面上有 1 个元素可以通过 xpath 定位
//li[@class='product-item--row js_item_root ']//*[contains(text(), '${companyname}')]
我想知道,在这 24 个元素中,元素所在的位置包含了哪些
//*[contains(text(), '${companyname}')]
希望有人能提供帮助!
编辑
这不起作用:
Element should be visible ${item}//*[contains(text(), 'BargainsKing')]
那是因为:
Element with locator '<selenium.webdriver.remote.webelement.WebElement (session="4b40581d8835aac628e3a2032e355ee5", element="663438f7-76eb-4801-b255-021a865035dd")>//*[contains(text(), 'BargainsKing')]' not found.
编辑
我找到了
${item.get_attribute('innerHTML')}
现在我的下一个/最后一个问题是,我可以在这个 innerHTML 中查找一个 xpath 吗?
【问题讨论】:
标签: xpath robotframework