Unable to click a button when an alert is displayed in the background #7666

Open
nchinenk opened this Issue Jan 10, 2017 · 5 comments

Projects

None yet

3 participants

@nchinenk

I have this command:

wd.find_element_by_xpath("//XCUIElementTypeButton[@name='Cancel']").click()

or using full Xpath:

wd.find_element_by_xpath("//XCUIElementTypeApplication[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[3]/XCUIElementTypeOther[2]/XCUIElementTypeButton[2]").click()

which no matter what time out I set returns an error: An element could not be located on the page using the given search parameters.

I'm running Appium 1.6.3 from the Terminal and in its log I see the following:

[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/F5298351-AA27-43B7-AA22-B5CAAD72CD04/element] with body: {"using":"xpath","value":"//XCUIElementTypeApplication[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[3]/XCUIElementTypeOther[2]/XCUIElementTypeButton[2]"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":"Alert is obstructing view","sessionId":"F5298351-AA27-43B7-AA22-B5CAAD72CD04","status":26}
[HTTP] <-- POST /wd/hub/session/9843786c-bd74-4566-87df-3e99d7c82272/element 500 3776 ms - 164

I know there is an alert box behind the window where I try to click the button to close it, so I can get to that alert, but it won't let me.

I think based on the Appium log the alert which is displayed in the background somehow prevent the window on top of it from being discovered, but not sure how to solve that.

@triager triager added the NeedsTriage label Jan 10, 2017
@mykola-mokhnach
Collaborator

What happens if you call driver.switchTo().alert().accept() to accept the alert first?

@nchinenk

I'm getting an error for this line of code you provided:

AttributeError: 'WebDriver' object has no attribute 'switchTo'

@mykola-mokhnach
Collaborator

in python this might have different name. Try switch_to

@nchinenk

I used wd.switch_to().alert().accept(). Now the following error appears:

AttributeError: MobileSwitchTo instance has no call method

Sorry, I've never used this method before. Trying to find out what the syntax in Python is for it.

Thanks!

@nchinenk

wd.switch_to_alert().accept() worked, but it still doesn't find the button and displays same error in the terminal Appium log: Alert is obstructing view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment