D
D
Damen Damen2017-09-26 10:00:58
Python
Damen Damen, 2017-09-26 10:00:58

Does not click on the element, how to solve?

I have such a function (yes, I know, shit code, don't throw stones, I just started learning python)
In theory, here you should click on the "basket" and the "Yes \ No" sign will appear and click on the "Yes" button. But this dog clicks on the basket and does not want to click on "Yes"

def del_post(self):
        wait = WebDriverWait(self.driver, 10)
        self.driver.implicitly_wait(10)
        self.driver.find_elements_by_class_name('fa-trash')[0].click()
        self.driver.implicitly_wait(10)
        element = wait.until(EC.element_to_be_clickable(
            (By.CSS_SELECTOR, 'div.event - header>div.event-controls>ul>li.event-menu.ng-scope>i>delete-confirm>'
                              'button.btn.btn-small.red.waves-effect.waves-light')))
            #(By.XPATH, '//*/div[1]/div[3]/ul/li[3]/i/delete-confirm/button[1]'))).click()
        time.sleep(2)
        return element.click()

HTML
<i class="fa fa-trash ng-isolate-scope" delete-confirm-open="$ctrl.removeTopic($event)" aria-hidden="true">
<delete-confirm on-delete="onDelete()" class="ng-scope ng-isolate-scope">
<button class="btn btn-small red waves-effect waves-light" ng-click="$ctrl.close(true)">Да
</button>
<button class="btn btn-small green waves-effect waves-light" ng-click="$ctrl.close()">Нет
</button>
</delete-confirm></i>

Tried on XPath, the exact same garbage.
traceback
Message: stale element reference: element is not attached to the page document

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Grigoriev, 2017-09-26
@uWotM8

A full stacktrace would be helpful, but Stale Gingerbread Divination suggests that the problem is in the line
And judging by the error, the element is either no longer on the page or it has been updated.
take a screenshot from the driver, at the time of the error, and see if it exists or not.
remove all unnecessary slips.

G
gill-sama, 2017-09-26
@gill-sama

you need to go to the confirmation frame. it doesn't exist in your code.
something like self.driver.switch_to_alert() before the element is selected

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question