Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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 文本中有撇号(';)的元素的定位器问题_Selenium_Xpath - Fatal编程技术网

Selenium 文本中有撇号(';)的元素的定位器问题

Selenium 文本中有撇号(';)的元素的定位器问题,selenium,xpath,Selenium,Xpath,我必须找到文本-‘收件人’电子邮件地址的格式不正确-使用xpath。下面的xpath对我来说很好 (//*[contains(.,"'To' email address is formatted incorrectly.")])[5] 但是当我把这个xpath放在我的定位器中时 @FindBy(xpath="(//*[contains(.,"'To' email address is formatted incorrectly.")])[5]") public WebElement incor

我必须找到文本-‘收件人’电子邮件地址的格式不正确-使用xpath。下面的xpath对我来说很好

(//*[contains(.,"'To' email address is formatted incorrectly.")])[5]
但是当我把这个xpath放在我的定位器中时

@FindBy(xpath="(//*[contains(.,"'To' email address is formatted incorrectly.")])[5]") public WebElement incorrectEmailFormatLabel;
我收到代码中的警告错误消息。我知道这是因为使用了双引号(“'To'…”),但如果我将其更改为单引号(“'To'…”),我会收到此错误消息

invalid selector: Unable to locate an element with the xpath expression (//*[contains(.,''To' email address is formatted incorrectly.')])[5]
让我知道如何解决它?我也跟帖了,这里xpath对我不起作用

(//*[contains(.,\" 'To' email address is formatted incorrectly.\")])[5]

在问题中,您使用
\
帮助提供了节目

试试这个:

@FindBy(xpath="(//*[contains(.,\"\'To\' email address is formatted incorrectly.\")])[5]") public WebElement incorrectEmailFormatLabel;

希望这有帮助

哦,是的,成功了。我曾在chropath中尝试xpath,但它不起作用,但当放入定位器时,它起作用了,谢谢。@ShoaibAkhtar很高兴能提供帮助!