Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Exception when switching to alert window #3565

Closed
lukeis opened this issue Mar 3, 2016 · 25 comments
Closed

Exception when switching to alert window #3565

lukeis opened this issue Mar 3, 2016 · 25 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 3565

What steps will reproduce the problem?
1. switch to alert window
2.
3.

What is the expected output? What do you see instead?
java.lang.Boolean cannot be cast to java.lang.String (java.lang.ClassCastException)


Selenium version: 2.20.0
OS: Windows XP
Browser: Remote Firefox
Browser version: 11






Switching to alert
[remote server] org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator(RemoteWebDriver.java):698:in
`alert': java.lang.Boolean cannot be cast to java.lang.String (java.lang.ClassCastException)
(Selenium::WebDriver::Error::UnknownError)
        from [remote server] org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator(EventFiringWebDriver.java):589:in
`alert'
        from [remote server] org.openqa.selenium.remote.server.handler.GetAlertText(GetAlertText.java):32:in
`call'
        from [remote server] org.openqa.selenium.remote.server.handler.GetAlertText(GetAlertText.java):1:in
`call'
        from [remote server] java.util.concurrent.FutureTask$Sync():-1:in `innerRun'
        from [remote server] java.util.concurrent.FutureTask():-1:in `run'
        from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker():-1:in
`runTask'
        from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker():-1:in
`run'
        from [remote server] java.lang.Thread():-1:in `run'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:52:in
`assert_ok'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:15:in
`initialize'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`new'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`create_response'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/default.rb:64:in
`request'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:40:in
`call'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:594:in
`raw_execute'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:572:in
`execute'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:139:in
`getAlertText'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/alert.rb:9:in
`initialize'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/target_locator.rb:76:in
`new'
        from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/target_locator.rb:76:in
`alert'


Reported by tech.herry on 2012-03-14 21:28:56

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

We're going to need a full reproduction case; ruby code, and HTML+javascript+css or
a live URL we can visit, to fix this.

Reported by dawagner on 2012-03-17 23:23:27

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

<<<< HTML >>>>

<td align="center">
<a onmouseout="nd(); return true;" onmouseover="overlib('Delete')" href="javascript:localDelete('object')">
<img width="16" height="16" border="0" src="/Images/Common/delete.gif">
</a>
</td>

<<<<JS>>>

function localDelete(item)
{
var lf = top.frames[1].frames[1].frames[1].document.localForm;
if (!confirm("Are you sure you want to\npermanently remove this " + item + "?"))
{
lf.reset();
}
else
{

onSubmitHandler();
lf.CMD.value = "delete";
lf.submit();
}
} 
<<< HTML Form >>>

<form method="POST" target="middle" enctype="multipart/form-data" action="services.origin.FileAction.action"
name="localForm">
<input type="hidden" value="true" name="postback">
<input type="hidden" value="" name="FIELD">
<input type="hidden" value="" name="SORT">
<input type="hidden" value="" name="pageName">
<input type="hidden" value="modify" name="CMD">




<<<<Ruby scripts>>>>


      del_button = @driver.find_element(:xpath,'/html/body/table/tbody/tr/td/table/tbody/tr/td[2]/a')
        #@driver.action.move_to(del_button).perform
        if @browser_type == 'firefox'
            @driver.manage.timeouts.page_load = 3
            @driver.manage.timeouts.script_timeout = 2
        end
        begin
            del_button.click()
        rescue Selenium::WebDriver::Error::ScriptTimeOutError => e
        #rescue Selenium::WebDriver::Error::TimeOutError => e
        #rescue Timeout::Error => e
        end
        #@driver.find_element(:xpath,'/html/body/table/tbody/tr/td/table/tbody/tr/td[2]/a').send_keys("\n")
        #@driver.execute_script('localDelete(\'object\')')
        windows = @driver.window_handles
        windows.each { |win| puts win}
        #frs = @driver.find_elements(:tag_name,'frame')
        #frs.each { |fr| puts fr}
        begin
            puts 'Switching to alert'
            a = @driver.switch_to.alert
            #puts a.text
            a.accept
        rescue Selenium::WebDriver::Error::NoAlertPresentError => e
        end


<<<<On Windows: >>>

{b0dfbf60-204d-47c6-b58e-83e6f709127a}
Switching to alert
[remote server] org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator(RemoteWebDriver.java):698:in
`alert': java.lang.Boolean cannot be cast to java.lang.String (java.lang.ClassCastException)
(Selenium::WebDriver::Error::UnknownError)
    from [remote server] org.openqa.selenium.support.events.EventFiringWebDriver$EventFiringTargetLocator(EventFiringWebDriver.java):589:in
`alert'
    from [remote server] org.openqa.selenium.remote.server.handler.GetAlertText(GetAlertText.java):32:in
`call'
    from [remote server] org.openqa.selenium.remote.server.handler.GetAlertText(GetAlertText.java):1:in
`call'
    from [remote server] java.util.concurrent.FutureTask$Sync():-1:in `innerRun'
    from [remote server] java.util.concurrent.FutureTask():-1:in `run'
    from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker():-1:in `runTask'
    from [remote server] java.util.concurrent.ThreadPoolExecutor$Worker():-1:in `run'
    from [remote server] java.lang.Thread():-1:in `run'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:52:in
`assert_ok'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:15:in
`initialize'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`new'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`create_response'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/default.rb:64:in
`request'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:40:in
`call'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:594:in
`raw_execute'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:572:in
`execute'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:139:in
`getAlertText'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/alert.rb:9:in
`initialize'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/target_locator.rb:76:in
`new'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/target_locator.rb:76:in
`alert'
    from ./cms_wb_api.rb:357:in `delete'
    from ./cms_wb_api.rb:370:in `del_nas'
    from test-cms.rb:51

<<<<On Ubuntu, localhost >>>

remote server] file:///tmp/webdriver-profile20120319-21364-115eaoc/extensions/fxdriver@googlecode.com/components/command_processor.js:9434:in
`unknown': Timed out waiting for page load. (Selenium::WebDriver::Error::TimeOutError)
    from [remote server] file:///tmp/webdriver-profile20120319-21364-115eaoc/extensions/fxdriver@googlecode.com/components/command_processor.js:8668:in
`unknown'
    from [remote server] file:///tmp/webdriver-profile20120319-21364-115eaoc/extensions/fxdriver@googlecode.com/components/command_processor.js:8674:in
`unknown'
    from [remote server] file:///tmp/webdriver-profile20120319-21364-115eaoc/extensions/fxdriver@googlecode.com/components/command_processor.js:8585:in
`unknown'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:52:in
`assert_ok'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/response.rb:15:in
`initialize'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`new'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:59:in
`create_response'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/default.rb:64:in
`request'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/http/common.rb:40:in
`call'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:594:in
`raw_execute'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:572:in
`execute'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/remote/bridge.rb:354:in
`clickElement'
    from /usr/lib/ruby/gems/1.8/gems/selenium-webdriver-2.20.0/lib/selenium/webdriver/common/element.rb:34:in
`click'
    from ./cms_wb_api.rb:344:in `delete'
    from ./cms_wb_api.rb:370:in `del_nas'
    from test-cms.rb:51

Reported by hailiangwang on 2012-03-19 19:10:54

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

anyone could help ?
Still have this issue with 2.21.

Reported by tech.herry on 2012-04-17 19:38:14

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

We're facing the same issue in Java:
{code}
java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
        at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:688)
{code}
Selenium version: 2.16.1
OS: Linux
Browser: Firefox 9.0.1

Reported by phil@linxo.com on 2012-04-18 17:16:05

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

seems to work with v.2.22.0 and FF 12

Reported by klaus.pfe on 2012-05-30 11:25:14

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I see this same issue using Java.

Alert alert = browser.switchTo().alert();

Exception:
java.lang.Boolean cannot be cast to java.lang.String

org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:734)


WD version: 2.22.0
OS: Linux
Browser: FF 3.6.24

Reported by david.w.andrews on 2012-06-07 19:02:54

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue is reproduced using Java for me as well.
WD version: 2.25
OS: Linux
Browser: FF 

Here is a part of WD code which cause this issue (org.openqa.selenium.remote.RemoteWebDriver):

public Alert alert() {
Response response = RemoteWebDriver.this.execute("getAlertText");
return new RemoteWebDriver.RemoteAlert(RemoteWebDriver.this, (String)response.getValue());
}

Reported by andrei.varabyeu on 2012-09-03 16:19:34

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reproduced Issue

WD: 2.26
OS: Win 7
Browser: FF 12

public Alert alert() {
      Response response = execute(DriverCommand.GET_ALERT_TEXT);
      return new RemoteAlert((String) response.getValue());
    }

Reported by davidpaterson@live.co.uk on 2012-11-22 13:16:20

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Hi ,

I am facing the same issue when switching to alert.This is happening 2 or 3 times out
of 200 times.

WD:2.25
OS:Windows server 2008
Browser:FF12

please help me how can i fix this.

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.alert(RemoteWebDriver.java:775)

Reported by sreenu.gopu on 2013-02-02 11:05:55

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I am seeing the same issue (ClassCastException in the same code block as above)

WD: 2.28
FF: 17
OS: Win 7, Win 2008

Reported by JimRAnderson on 2013-02-12 20:34:46

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I should note this is with the Java driver.

Reported by JimRAnderson on 2013-02-12 20:39:14

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

In selenium 2.30 the error message will contain more information, we hope to be able
to  understand the root cause then.

Reported by barancev on 2013-02-13 07:37:43

  • Status changed: Started
  • Labels added: Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

For what it's worth, I've been able to consistently reproduce the issue in my environment
by executing two separate actions that cause alerts, and calling selenium.getAlert()
after each action.  The second call to getAlert is throwing the ClassCastException.


Reported by JimRAnderson on 2013-02-13 23:51:50

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

@JimRAnderson: Would you please share a piece of code instead of text description? What
do you mean by "executing two separate actions that cause alerts"?

Reported by barancev on 2013-02-15 10:10:16

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Can anybody having the issue retest it and tell us the diagnostic message that should
contain more details now?

Reported by barancev on 2013-05-20 18:50:39

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by a.u.savchuk on 2013-08-02 23:09:55

  • Labels added: Component-WebDriver

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Closing due to inactivity. Please ask to reopen if the issue is still actual.

Reported by barancev on 2013-08-15 16:36:56

  • Status changed: Fixed

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I see this same issue using Java. Happens when 2 test cases run sequentially. There
is no error where running each test separately.

Alert alert = browser.switchTo().alert();

Exception:
ava.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String at
org.openqa.selenium.remote.RemoteWebDriver$RemoteAlert.getText(RemoteWebDriver.java:867)

866 public String getText() {
867      return (String) execute(DriverCommand.GET_ALERT_TEXT).getValue();
868 }

WD version: 2.25.0
OS: Windows 7 Professional
Browser: FF 22.0

Reported by badong2210 on 2013-09-30 09:06:10

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

@badong2210: The latest version of Selenium is 2.35

Reported by barancev on 2013-09-30 16:28:44

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

This issue occurred with Selenium 2.40.0 (Java) and Firefox 25.0.1 (Windows) with local
execution.

An UnhandledAlertException was thrown during the test-execution (findElement) because
there was a "long running script" alert.

The a test fails, we are calling "driver.switchTo().alert()" to check if there is an
alert present and try to log out the text if an alert is present "LOGGER.log(Level.WARNING,
"Alert with text \"{0}\" was present and will be dismissed now...", alert.getText());"

Reported by OsswaldM94 on 2014-03-31 08:23:10

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Issue still exists in Selenium 2.42.2, it is not fixed!

java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.openqa.selenium.remote.RemoteWebDriver$RemoteAlert.getText(RemoteWebDriver.java:918)

thrown in:
    public String getText() {
      return (String) execute(DriverCommand.GET_ALERT_TEXT).getValue();
    }

whereas here it is used without cast, but using toString()

  public String getCurrentUrl() {
    return execute(DriverCommand.GET_CURRENT_URL).getValue().toString();
  }

which would probably solve the problem at least regarding the exception. Why it's a
boolean in the first place, I have no idea, the alert window clearly contains a lot
of text.

Reported by asbytes on 2014-07-24 08:38:04

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

@asbytes: Please provide a sample page and a scenario to reproduce the issue.

Reported by barancev on 2014-07-24 08:40:44

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I get the same issue on selenium 2.43.1 and Firefox 24ESR.

- Load the page http://www.tacobell.com/tacobell/store-locator/
- fill the input element .//*[@id='findUsZip'] with the value "OR"
- click on the eleemnt .//*[@id='findUsZipGo'] to submit the form
- An alert will popup after a few seconds
- Alert alert = browser.switchTo().alert().getText()

will result in java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String

Reported by giovannigrasso on 2015-01-20 15:14:59

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

2.44 as well.

Reported by sergio@systextil.com.br on 2015-01-22 20:27:17

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:15:03

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant