Reputation: 21
I have the problem of running this. I get back an error stating that I have a syntax issue. Ineed help with the Syntax.
driver.execute_script('$('select[name='condition'] option:eq(30)').prop('selected', true);') ^ SyntaxError: invalid syntax
driver.execute_script("$('select[name='condition'] option:eq(30)').prop('selected', true);")
Upvotes: 1
Views: 7209
Reputation: 3790
So if jquery is not on the page you need to add it first. I am just appending it to the page below. Then run your code.
driver.execute_script("""
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js';
document.head.appendChild(script);
""")
driver.execute_script("$('select[name='condition'] option:eq(30)').prop('selected', true);")
More jquery links can be found at: https://code.jquery.com/
Upvotes: 2
Reputation: 55002
driver.execute_script("""
$('select[name="condition"] option:eq(30)').prop('selected', true);
""")
You can also leave out the quotes in the attribute to be safer (since there are no spaces)
driver.execute_script("""
$('select[name=condition] option:eq(30)').prop('selected', true);
""")
Upvotes: 0