语法错误:无法在“文档"上执行“评估":字符串"//img [contains('1236548597')]"不是有效的XPath表达式 [英] SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//img[contains('1236548597')]' is not a valid XPath expression

查看:187
本文介绍了语法错误:无法在“文档"上执行“评估":字符串"//img [contains('1236548597')]"不是有效的XPath表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到语法错误:

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//img[contains('1236548597')]' is not a valid XPath expression.

我的代码:

enter_chat = driver.find_element_by_xpath("//img[contains('1236548597')]")
enter_chat.click()

推荐答案

此错误消息...

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//img[contains('1236548597')]' is not a valid XPath expression.

...表示您使用的 XPath 不是有效的 XPath 表达式.

...implies that the XPath which you have used was not a valid XPath expression.

在代码试用中,具有contains()函数的谓词有问题.

In your code trial the predicate with contains() function has an issue.

  • contains()接受两个参数.第一个参数始终是要测试的属性,第二个参数是要查找的 value .第一个参数应该是属性,其中包含值 1236548597 :

  • contains() accepts two parameters. The first parameter is always the attribute to be tested and the second parameter is the value to lookout for. The first parameter should have been the attribute which contains the value 1236548597:

enter_chat = driver.find_element_by_xpath("//img[contains(@<attributeName>,'1236548597')]")

在没有相关HTML的情况下构造答案很困难.但是,两种可能的解决方案如下:

It would be tough to construct an answer without the relevant HTML. However two possible solutions are as follows:

  • 如果标签是<a>标签,且包含img 属性,且该标签包含值 1236548597 :

  • If the tag is a <a> tag, containing an img attribute containing the value 1236548597:

enter_chat = driver.find_element_by_xpath("//a[contains(@img,'1236548597')]")

  • 如果标签是<img>标签,且包含src 属性,且该标签包含值 1236548597 :

  • If the tag is a <img> tag, containing an src attribute containing the value 1236548597:

    enter_chat = driver.find_element_by_xpath("//img[contains(@src,'1236548597')]")
    

  • 这篇关于语法错误:无法在“文档"上执行“评估":字符串"//img [contains('1236548597')]"不是有效的XPath表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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