在硒Python中执行jQuery? [英] execute Jquery in selenium Python?

查看:59
本文介绍了在硒Python中执行jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有运行此文件的问题.我收到一条错误消息,指出我有语法问题.获得有关语法的帮助.

driver.execute_script('$('select [name ='condition'] option:eq(30)').prop('selected',true);')^SyntaxError:语法无效

  driver.execute_script("$('select [name ='condition']选项:eq(30)').prop('selected',true);") 

解决方案

因此,如果页面上没有jquery,则需要先添加它.我只是将其附加到下面的页面.然后运行您的代码.

  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);") 

更多jquery链接可在以下位置找到: https://code.jquery.com/

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);")

解决方案

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/

这篇关于在硒Python中执行jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆