元素定位突然不能使用了,前面的正常執行,執行 self.driver.find_element (*self.ele.addContent).send_keys (content) 時報錯

樹苗發表於2020-06-15

dynamicTab =(By.ID,'dynamicTab')
dynamicAdd =(By.ID,'dynamicAdd')
releaseButton =(By.ID,'addDynamicSave')
addContent =(By.ID,'/addDynamicContent')
addPictureVideo =(By.ID,'itemAlbumImage')
addPicture = (By.XPATH,"//android.widget.TextView[@text='新增照片']")
addVideo = (By.XPATH,"//android.widget.TextView[@text='新增視訊']")
cancelButton =(By.ID,'cancelButton')

def dynamic_action(self):
logging.info('========>dynamic_action')
self.driver.find_element(*self.ele.dynamicTab).click()
self.driver.find_element(*self.ele.dynamicAdd).click()
self.driver.find_element(*self.ele.addPictureVideo).click()

def release_content(self,content):
logging.info('========>release_content')
self.dynamic_action()
self.driver.find_element(*self.ele.cancelButton).click()
self.driver.find_element(*self.ele.addContent).send_keys(content)
self.driver.find_element(*self.ele.releaseButton).click()

報錯資訊:

self.driver.find_element(*self.ele.addContent).click()
File "C:\text\python\lib\site-packages\appium\webdriver\webdriver.py", line 279, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {
File "C:\text\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\text\python\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response
raise wde
File "C:\text\python\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
super().check_response(response)
File "C:\text\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

相關文章