Reputation: 23
I'm using selenium on python right now and I was wondering how to execute multi line commands to the console I am doing this command:
script = "alert('Test Alert')"
driver.execute_script(script)
Although I'm not sure how to make it so I can paste a multi-line piece of code for it to execute in the console
Upvotes: 0
Views: 445
Reputation: 2968
It's possible to execute the multiline command in the same way like single-line:
script = '''
a = function(b, c) {
return b + c;
}
return a(2, 2);
'''
print(driver.execute_script(script))
this will print 4
.
However, if you'll run the script with alert, the browser will be blocked until the alert is closed.
Please note, for this script:
script = '''
a = function(b, c) {
return b + c;
}
alert('Test Alert');
return a(2, 2);
'''
print(driver.execute_script(script))
this will print None
, but return a(2, 2)
line will be also executed;
Upvotes: 1