Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Python sel.click(";css=input.smthg";)?_Python_Css_Selenium_Click - Fatal编程技术网

Selenium Python sel.click(";css=input.smthg";)?

Selenium Python sel.click(";css=input.smthg";)?,python,css,selenium,click,Python,Css,Selenium,Click,我正在用Python为Selenium编写脚本,但是当选择是CSS时,“sel.click”操作不起作用: def test_test_remote(self): sel = self.selenium sel.open("/fr") sel.click("id=flightFrom") sel.type("id=flightFrom", "Londres-Stansted") sel.type("id=flightTo", "Dublin") s

我正在用Python为Selenium编写脚本,但是当选择是CSS时,“sel.click”操作不起作用:

def test_test_remote(self):
    sel = self.selenium
    sel.open("/fr")
    sel.click("id=flightFrom")
    sel.type("id=flightFrom", "Londres-Stansted")
    sel.type("id=flightTo", "Dublin")
    sel.click("id=termsAccept")
    sel.click("css=input.bookFlightButton") ----> nothing happens
    sel.wait_for_page_to_load("30000")
有人有主意吗

问候


Vincent

这很可能是幕后Javascript代码造成的。当您使用浏览器浏览网站时,您可能只需单击元素,一切都会按预期进行。假设
input.bookFlightButton
实际上在其
mouseup
处理程序上处理提交请求,例如:您的
单击
命令可能会失败

我想尝试两件事。首先,检查是否无法使用Selenium的
submitform
命令提交表单。幸运的话,这会给你想要的结果

另一方面,您必须稍微插入Javascript。如果站点碰巧使用jQuery,请在浏览器中启动一个命令窗口(Chrome默认有此功能;对于Firefox,您需要Firebug,即…不知道)。然后尝试使用jQuery切换表单提交:

$('input.bookFlightButton').click()
$('input.bookFlightButton').mouseup()
找到有效的呼叫后,替换
sel。单击该按钮上的
,选择以下内容:

sel.get_eval("window.jQuery('input.bookFlightButton').mouseup()")

…将其从Selenium切换。

您是否可以提供HTML源代码,这可能是下面提到的有关javascript的问题