为什么selenium告诉我javascript代码中缺少了一个paranthases,而我没有?

为什么selenium告诉我javascript代码中缺少了一个paranthases,而我没有?,javascript,python,selenium,Javascript,Python,Selenium,这是我目前在selenium应用程序中使用的代码 容器_xpath='//a[开始-with@href,/direct/t/]/../../../../ def js_codecode=: 返回fdocument.evaluate'{container\u xpath}',document,null,XPathResult.FIRST\u ORDERED\u NODE\u TYPE,null.singleNodeValue;{code} code=f'console.log\{js_code}\

这是我目前在selenium应用程序中使用的代码

容器_xpath='//a[开始-with@href,/direct/t/]/../../../../ def js_codecode=: 返回fdocument.evaluate'{container\u xpath}',document,null,XPathResult.FIRST\u ORDERED\u NODE\u TYPE,null.singleNodeValue;{code} code=f'console.log\{js_code}\\' self.driver.execute_脚本代码 js_代码的输出:

document.evaluate('//a[starts-with(@href, "/direct/t/")]/../../..', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

这一切对我来说都很好,但是,当我运行此命令时,会在终端中抛出一个错误:selenium.common.exceptions.JavascriptException:Message:javascript error:missing after参数列表。谢谢你的帮助

定义Xpath时不能使用双引号 所以试着把它的形式从/direct/t/改为“/direct/t/”

如果这似乎也不起作用,那么将entre语句从

'//a[开始]-with@href,/direct/t/]/../../../../


//a[开始]-with@href,'/direct/t/']/../../../../p>什么是“js_代码”输出?@evolutionxbox document.evaluate'//a[开始]-with@href,/direct/t/]/../../..,document,null,XPathResult.FIRST\u ORDERED\u NODE\u TYPE,null.singleNodeValue;你确定吗?我以前在chrome中使用过双引号,效果很好。这不是我问题的解决方案