我有下面的函数,我想搜索元素,如果找到元素,我想删除它,然后再搜索它。请参阅下面的代码:
1)此代码验证存在的文本。在
def verifyText(self, text):
try:
self.switchToFrame(*MainPageLocatars.FRAMEONE)
self.switchToFrame(*MainPageLocatars.SUBLISTFRAME)
try:
self.text.find_element_by_xpath('//td[text() = "%s"]' % text)
except:
self.text.find_element_by_xpath('//td/span[text() = "%s"]' % text)
except:
try:
self.text.find_element_by_xpath('//td[text() = "%s"]' % text)
except:
self.text.find_element_by_xpath('//td/span[text() = "%s"]' % text)
2)这个删除找到的元素
^{pr2}$3)然后我编写了一个函数来查看元素是否被删除。我不想再编写verify text函数,所以我使用了这个函数。这样写对吗?在
def verifyElement(self, text):
if verifyText:
raise Exception("Element could not be deleted")
else:
pass
您可以重新编写
verifyText()
,如下所示:注意,}
//td[.="%s"]
同时匹配//td[text()="%s"]
和{{cd5>中可以使用它:
^{pr2}$相关问题 更多 >
编程相关推荐