我運行下面的代碼來驗證網頁上的文字:不斷收到元素沒有連接到網頁文件
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)每個步驟之後加入time.sleep但它仍然是給我一個錯誤,當我運行這個功能 - >>不斷得到元件沒有以這行代碼
self.row.find_element_by_xpath(ListViewLocatars.VERIFYTEXT % Text)
我在這裏調用該函數,我應該在哪裏重新定義它附加到頁面文件錯誤?
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
這可能是因爲頁面是因爲時間更新您已經聲明'row'元素,所以你不能再使用它了,但需要重新定義它 – Andersson
@Andersson,我需要在哪裏重新定義它?請參閱我的更新問題 – user7242550
顯示什麼是「行」,您如何定義它 – Andersson