萤火虫确定的XPath量角器不工作 [英] Firebug identified xpath not working in protractor

查看:165
本文介绍了萤火虫确定的XPath量角器不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

萤火虫鉴定的xpath不使用firebug.When我使用的IDE识别的xpath,它是工作fine.However当我使用在量角器相同的xpath在protractor.I工作ahve cretaed的xpath,它不是working.My元件不有ID或name.So在这里,我只能使用XPath的选项。

请找到参考下面的图片。
在这里,我需要验证特定元素是否具有IRCTC景点的文字。

您能帮我吗?

HTML code:

  // DIV的风格=宽度:100%;类=g_hedtext> IRCTC旅游/ DIV


解决方案

OK,看着你的错误信息(在评论)

 异常载荷:语法错误:
C:\\用户\\ XXXX \\应用程序数据\\漫游\\故宫\\ TC_model2.js:7
VAR disclaimermessage =元素(by.xpath('// [@ ID ='免责声明消息']'));
                                                  ^^^^^^^^^^意外的标识符

(我猜,其中前意外的标识符插入记号进行比对,对不对?)

问题是,你使用单引号既分隔字符串免责声明消息',并划定了整个的XPath前pression '// [@ ID ='免责声明消息'] 。因此,它似乎你的XPath前pression是前两个单引号之间的东西解析器:'// [@ ID =',然后在免责声明消息是没有任何逗号或其他运营商的一些其它标识符,以显示它在做什么在那里。

解决方案是使用XPath的前pression内双引号。 XPath的可以接受单或双引号;它并不关心,只要你与对方匹配。因此,问题的行更改为

  VAR disclaimermessage =元素(by.xpath('// [@ ID =免责声明消息]'));

和你应该是好去。

有关备查,这个问题将是更快,更容易回答,如果你告诉我们关于在首位的错误消息。

Firebug identified xpath not working in protractor.I ahve cretaed xpath using firebug.When I identify the xpath using IDE,it is working fine.However when I use the same xpath in protractor,it is not working.My element does not have id or name.So here i can use only xpath option.

Please find the below image for reference. Here I need to verify whether that particular element has "IRCTC Attractions" text.

Could you please help me?

HTML code:

//div style="width:100%;" class="g_hedtext">IRCTC Attractions /div

解决方案

OK, looking at your error message (in the comment):

Exception loading: SyntaxError:
C:\Users\XXXX\AppData\Roaming\npm\TC_model2.js:7
var disclaimermessage = element(by.xpath('//[@id='disclaimer-message']'));
                                                  ^^^^^^^^^^ Unexpected identifier

(I'm guessing where the carets before "Unexpected identifier" were aligned. Is that right?)

The problem is that you've used single quotes both to delimit the string 'disclaimer-message', and to delimit the whole XPath expression '//[@id='disclaimer-message']'. Thus it appears to the parser that your XPath expression is the stuff between the first two single quotes: '//[@id=', and then the disclaimer-message is some other identifier without any comma or other operator to show what it's doing there.

The solution is to use double quotes inside the XPath expression. XPath accepts either single or double quotes; it doesn't care, as long as you match them with each other. So change the offending line to

var disclaimermessage = element(by.xpath('//[@id="disclaimer-message"]'));

And you should be good to go.

For future reference, this question would have been quicker and easier to answer if you had told us about the error message in the first place.

这篇关于萤火虫确定的XPath量角器不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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