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
Javascript 尝试在(fillField)中使用XPath进行自动测试_Javascript_Xpath_Automated Tests_Codeception - Fatal编程技术网

Javascript 尝试在(fillField)中使用XPath进行自动测试

Javascript 尝试在(fillField)中使用XPath进行自动测试,javascript,xpath,automated-tests,codeception,Javascript,Xpath,Automated Tests,Codeception,尝试测试一些字段,当我选中“Inspect element”以标识字段的id或名称时,只有一个类不起作用,所以我决定使用XPath,例如: $I->fillField('/html/body/div/form/div[2]/div[3]/div/div[1]/label/span[1]','GRV'); 并获取失败和错误: 1) Couldn't sign in in Authorization Ups, I couldn't fill field "/html/body/div/f

尝试测试一些字段,当我选中“Inspect element”以标识字段的id或名称时,只有一个类不起作用,所以我决定使用XPath,例如:

$I->fillField('/html/body/div/form/div[2]/div[3]/div/div[1]/label/span[1]','GRV');
并获取失败和错误:

1) Couldn't sign in in Authorization  
Ups, I couldn't fill field "/html/body/div/form/div[2]/div[3]/div/div[1]/label/s
pan[1]","blabla",
Field by name, label, CSS or XPath '/html/body/div/form/div[2]/div[3]/div/div[1]
/label/span[1]' was not found on page.

我检查了几次XPath,无法测试此字段。如果您能告诉我们问题是什么以及如何解决它,那就太好了。

您尝试填充标签,而不是输入元素:

//标签/span[1]

请确保选择要填充的输入字段。如果标签的for属性值为“foo”,请查找

那么,请避免使用此类XPath。真是太棒了。你只是打破了你的想法,我们也在试图解决它:)只需将#id选择器添加到你匹配的元素中,并感到高兴


使用这种XPath的测试将在页面的每次标记更改时中断。为什么您需要一个如此难以维护的测试?

不,我刚才在示例xpath中犯了一个错误。实际上,我正在寻找像“//span/input[1]”这样的xapth。不管怎样,codeception生成的消息就像找不到元素:{“method”:“xpath”,“selector”:“//html”}。我想这正是我要写的。你的HTML看起来怎么样?当然我们可以在元素中添加#id选择器,但这将是最后一个选项。我们尝试使用长/短/XPath进行测试,但这两种方法都不起作用。尽管Codeception必须很好地使用XPath进行测试,但问题在哪里,如何使用XPath解决呢。