我正在运行以下代码以验证页面上的文本:
def verifyText(self, Text):
try:
self.switchToFrame(*MainPageLocatars.FRAMEONE)
self.switchToFrame(*MainPageLocatars.SUBLISTFRAME)
except:
pass
self.row.find_element_by_xpath(ListViewLocatars.VERIFYTEXT % Text)
我试着补充时间。睡觉(2) 在每一步之后,当我运行此函数时仍然会给我一个错误->Keep get element not attached to the page document error at this line code
^{pr2}$我在这里调用函数,我应该在哪里重新定义它?在
listview = ListView(self.driver, 'First')
listview.verifyText("comp1")
请注意,行是父行:
self.row = self.driver.find_element_by_xpath(ListViewLocatars.ROWPARENT % INDEX_MAP[index])
我是这样定义函数的:
class ListView(Page):
def __init__(self, driver, index):
if index not in INDEX_MAP:
raise ValueError("Invalid index %s" % index)
self.driver = driver
try:
self.row = self.driver.find_element_by_xpath(ListViewLocatars.ROWPARENT % INDEX_MAP[index])
# used for VerifyText function only
except:
self.row = self.driver.find_element_by_xpath(ListViewLocatars.TEXTPARENT % INDEX_MAP[index])
def verifyText(self, Text):
try:
self.switchToFrame(*MainPageLocatars.FRAMEONE)
self.switchToFrame(*MainPageLocatars.SUBLISTFRAME)
except:
pass
self.row.find_element_by_xpath(ListViewLocatars.VERIFYTEXT % Text)
以下是完整代码:
# all locaters for this class are defined here only
class ListView(Page):
def __init__(self, driver, index):
if index not in INDEX_MAP:
raise ValueError("Invalid index %s" % index)
self.driver = driver
try:
self.row = self.driver.find_element_by_xpath(ListViewLocatars.ROWPARENT % INDEX_MAP[index])
# used for VerifyText function only
except:
self.row = self.driver.find_element_by_xpath(ListViewLocatars.TEXTPARENT % INDEX_MAP[index])
@property
def row(self):
return self.driver.find_element_by_xpath(ListViewLocatars.ROWPARENT % INDEX_MAP[index])
def verifyText(self, Text):
try:
self.switchToFrame(*MainPageLocatars.FRAMEONE)
self.switchToFrame(*MainPageLocatars.SUBLISTFRAME)
except:
pass
self.row.find_element_by_xpath(ListViewLocatars.VERIFYTEXT % Text)
它现在给我这个错误:
Traceback (most recent call last):
File "autoLoaderTest.py", line 56, in test02_AutoLoaderSubCompany
listview = ListView(self.driver, 'First')
File "C:\Users\cverma\Desktop\SOAPProject\mainPage.py", line 44, in __init__
self.row = self.driver.find_element_by_xpath(ListViewLocatars.TEXTPARENT % INDEX_MAP[index])
AttributeError: can't set attribute
这是如何触发
StaleElementReferenceException
以及如何避免它的简化版本。在我想您的代码如下所示:
如何避免:
^{pr2}$相关问题 更多 >
编程相关推荐