Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alert = driver().switch_to.alert alert.accept() throws NoAlertPresentException #128

Closed
byakatat opened this issue Apr 27, 2017 · 12 comments
Closed

Comments

@byakatat
Copy link

When i use selene and try to accept alert:

config.browser_name = Browser.CHROME

alert = driver().switch_to.alert
alert.accept()

I get this error:
......\MobilePages\RecipientPageM.py:23: in choose_recipient_from_list
alert.accept()
..........\selene-virt\lib\site-packages\selenium\webdriver\common\alert.py:80: in accept
self.driver.execute(Command.ACCEPT_ALERT)
..........\selene-virt\lib\site-packages\selenium\webdriver\remote\webdriver.py:233: in execute
self.error_handler.check_response(response)
E selenium.common.exceptions.NoAlertPresentException: Message: no alert open
E (Session info: chrome=58.0.3029.81)
E (Driver info: chromedriver=2.29.461591

While when i use standart driver it works fine:

self.driver = webdriver.Chrome(ChromeDriverManager().install())

alert = self.driver.switch_to.alert
alert.accept()
@SergeyPirogov
Copy link
Contributor

@byakatat are you sure that alert apears? Selene don't wait for alert to appear

@byakatat
Copy link
Author

@SergeyPirogov I'm absolutely sure.
I even tried to put time.sleep(10) before switch to alert, but it also doesn't work. Alert appears and after 10 sec i got this error.
As I said when i use standard driver it works fine without any waitings for alert to present.

@SergeyPirogov
Copy link
Contributor

And this is simple web application? Not Angular or something else?

@byakatat
Copy link
Author

@SergeyPirogov yes, it's simple web app. Here is a screenshot of alert https://yadi.sk/i/qi-MXW3V3HTHQg

@yashaka
Copy link
Owner

yashaka commented May 15, 2017

will look into it...

@yashaka
Copy link
Owner

yashaka commented May 15, 2017

Hm... We have tests for alerts: https://github.com/yashaka/selene/blob/master/tests/integration/test_alert.py

And they pass... That means that something may be wrong with your alert, @byakatat :)

Can you share link to production site? So we can look more closely what kind of alert do you have?

@byakatat
Copy link
Author

@yashaka
Sure. Use Chrome browser.

  1. Login here login page
    with email: tsz73303@tipsb.com and password: 123456
  2. Click on the logo on the left top corner - a main page will be opened
  3. Click on any bouquet - a bouquet page will be opened
  4. Click "Оформить заказ" button - a cart page will be opened
  5. Click "Оформить заказ" button again - a delivery date page will be opened
  6. Click "Следующий шаг" button - a recipient page will be opened
  7. And here you should choose recipient from dropdown, look here https://yadi.sk/i/pAdyELYD3JC9Sm
    and allert will appear.

And as I mentioned, when I use standard driver tests pass.

@yashaka
Copy link
Owner

yashaka commented May 16, 2017 via email

@aleksandr-kotlyar
Copy link
Collaborator

aleksandr-kotlyar commented Jan 2, 2021

Check

I have checked the situation in actual 2.0.34a selene core api version. And there is no problem.

I resurrected alert tests for 2.0.34a core api: 8b53e71 and ensured that they work fine.

import os
import pytest
from selenium import webdriver
from selenium.common.exceptions import NoAlertPresentException
from webdriver_manager.chrome import ChromeDriverManager
from selene import Config, Browser

start_page = 'file://' + os.path.abspath(os.path.dirname(__file__)) + '/../resources/start_page.html'


@pytest.fixture(scope='session')
def session_driver():
    chrome_driver = webdriver.Chrome(ChromeDriverManager().install())
    yield chrome_driver
    chrome_driver.quit()


@pytest.fixture(scope='function')
def session_browser(session_driver):
    yield Browser(Config(driver=session_driver))


def test_can_accept_alert(session_browser):
    session_browser.open(start_page)

    session_browser.element("#alert_btn").click()
    session_browser.driver.switch_to.alert.accept()

    try:
        session_browser.driver.switch_to.alert
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True


def test_can_dismiss_confirm_dialog(session_browser):
    session_browser.open(start_page)

    session_browser.element("#alert_btn").click()
    session_browser.driver.switch_to.alert.dismiss()

    try:
        session_browser.driver.switch_to.alert
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True


def test_alert_is_present(session_browser):
    session_browser.open(start_page)

    session_browser.element("#alert_btn").click()

    try:
        session_browser.driver.switch_to.alert
        assert True
    except NoAlertPresentException:
        assert False, 'actual: alert not present, expected: alert is present'

Suggestion

The problem of TC could be in selene version 1.0.10a because it hadn't clear and consistent api yet. There is no code to check he used selene api properly.

I upped tests of selene version 1.0.10a too, and had the trouble with the api, cause

from selene.browser import driver, visit

visit(page)
driver().switch_to.alert.accept()

driver() function opened new window instead of shared driver from visit() method.

So the script of calling alert in selene 1.0.10a should look like in tests below:

import os
from time import sleep

from selenium.common.exceptions import NoAlertPresentException

from selene import factory, browser

start_page = 'file://' + os.path.abspath(os.path.dirname(__file__)) + '/../resources/start_page.html'


# todo: ensure works and enabled
def test_can_accept_alert():
    browser.visit(start_page)

    browser.element("#alert_btn").click()
    shared_driver = factory.get_shared_driver()
    shared_driver.switch_to.alert.accept()

    try:
        shared_driver.switch_to.alert.accept()
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True


def test_can_dismiss_confirm_dialog():
    browser.visit(start_page)

    browser.element("#alert_btn").click()
    shared_driver = factory.get_shared_driver()
    shared_driver.switch_to.alert.dismiss()

    try:
        shared_driver.switch_to.alert.dismiss()
        assert False, 'actual: alert presents, expected: alert not present'
    except NoAlertPresentException:
        assert True

Resolution

Issue not reproduced. The problem could be in not proper usage of the selene - check the "Suggestion" block above.

Issue can be closed until we see the whole code with imports which TC has used to reproduce the issue.

@aleksandr-kotlyar
Copy link
Collaborator

Seems it could be this bug #117.
This bug has been fixed in #118.

@aleksandr-kotlyar
Copy link
Collaborator

@byakatat does this problem still actual on selene v2.0.0a34? Can you provide more details please, because UI from your example has been changed and that's why i cannot reproduce your case. But we have selene tests which shows up it's working now and i found PR which should fix this problem.

Seems it could be this bug, the same issue at the same time #117.
This bug has been fixed in PR #118.

@yashaka
Copy link
Owner

yashaka commented Jan 5, 2021

So, after all discussions... This seems to be not a bug.

Yet, the discussion revealed the topic of "waiting for alert". I have created a separate issue for that: #248

@yashaka yashaka closed this as completed Jan 5, 2021
Selene 2.0.0 stable release automation moved this from In progress to Done Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants