Note that there are some explanatory texts on larger screens.

plurals
  1. POSelenium Desired Capabilities - set handlesAlerts for PhantomJS driver
    primarykey
    data
    text
    <p>I'm trying out phantomJS with webdriver and I'm having trouble with handling javascript alerts. I notice the phantomjs driver desired_capabilities has a field <code>'handlesAlerts': False</code> Is there a way to set this value to true? I've tried the obvious way but that doesn't have any effect:</p> <pre><code>drv = webdriver.PhantomJS(desired_capabilities={'handlesAlerts': True}) print drv.desired_capabilities {u'browserName': u'phantomjs', u'driverName': u'ghostdriver', u'driverVersion': u'1.0.3', u'handlesAlerts': False, u'javascriptEnabled': True,...} </code></pre> <p>I can change the value in the dictionary <code>drv.desired_capabilities['handlesAlerts'] = True</code>, but when I try to switch to an alert, I get an error message.</p> <pre><code>$cat index.html &lt;html&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; alert('FOO!'); &lt;/script&gt; Hello World. &lt;/body&gt; &lt;/html&gt; &gt;&gt;&gt; from selenium import webdriver &gt;&gt;&gt; driver = webdriver.PhantomJS() &gt;&gt;&gt; driver.desired_capabilities['handlesAlerts'] = True &gt;&gt;&gt; driver.get('index.html') &gt;&gt;&gt; alert = driver.switch_to_alert() &gt;&gt;&gt; alert.text Traceback (most recent call last): &lt;snip&gt; selenium.common.exceptions.WebDriverException: Message: 'Invalid Command Method - Request =&gt; {"headers":{"Accept":"application/json", "Accept- Encoding":"identity", "Connection":"close", "Content-Type":"application/json;charset=UTF- 8", "Host":"127.0.0.1:56009", "User-Agent":"Python- urllib/2.7"}, "httpVersion":"1.1", "method":"GET", "url":"/alert_text", "urlParsed": {"anchor":"", "query":"", "file":"alert_text", "directory":"/", "path":"/alert_text", "relative":"/ alert_text", "port":"", "host":"", "password":"", "user":"", "userInfo":"", "authority":"", "protocol ":"", "source":"/alert_text", "queryKey":{}, "chunks":["alert_text"]}, "urlOriginal":"/session/cd31ed90-a5f8-11e2-856d-5783db9f5342/alert_text"}' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload