Selenium 断言css定位器等于它';s期望值

Selenium 断言css定位器等于它';s期望值,selenium,Selenium,我正在使用selenium客户端进行一些拖放js测试。它是有效的(在前后截屏清楚地显示要切换位置的元素),但是我在程序上断言发生了变化时遇到了麻烦 我是精神病患者,还是不能做以下事情: selenium.assert_equal(“css定位器”,“元素的预期id”) 在这种情况下,它看起来像: selenium.assert_equal(“css=li:nth child(1)”,“li#list_item_2”) 关于如何实现这一点的任何提示都将非常有用 谢谢 亚当 编辑:如果我有selen

我正在使用selenium客户端进行一些拖放js测试。它是有效的(在前后截屏清楚地显示要切换位置的元素),但是我在程序上断言发生了变化时遇到了麻烦

我是精神病患者,还是不能做以下事情:

selenium.assert_equal(“css定位器”,“元素的预期id”)

在这种情况下,它看起来像:

selenium.assert_equal(“css=li:nth child(1)”,“li#list_item_2”)

关于如何实现这一点的任何提示都将非常有用

谢谢

亚当

编辑:如果我有
selenium.get_元素
,它将接受一个选择器并返回它是什么,那么我可以在下一步执行断言

i、 e

element=selenium.get\u元素(“css=li:nth child(1)”)

assert_equal(元素,“li#list_item_2”)


(我认为)。

您的示例不起作用,因为您正在比较两个不相等的字符串。断言元素已移动的一种方法是使用
isElementPreset
,如下所示:

//before drag and drop
assertTrue(selenium.isElementPresent("css=#source li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#target li:nth-child(1)"));

//drag and drop code here
...

//after drag and drop
assertTrue(selenium.isElementPresent("css=#target li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#source li:nth-child(1)"));

本例使用Java客户机API,但在您首选的客户机API中应该很容易解决如何实现这一点。它还将在很大程度上取决于您的应用程序,因为上面将检查id为“target”的元素在拖放之前是否有一个子元素
li
元素,而在拖放之后则没有。如果您有一个HTML源代码片段,我可能能够证明一个更可靠的示例。

您的示例不起作用,因为您正在比较两个不相等的字符串。断言元素已移动的一种方法是使用
isElementPreset
,如下所示:

//before drag and drop
assertTrue(selenium.isElementPresent("css=#source li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#target li:nth-child(1)"));

//drag and drop code here
...

//after drag and drop
assertTrue(selenium.isElementPresent("css=#target li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#source li:nth-child(1)"));
本例使用Java客户机API,但在您首选的客户机API中应该很容易解决如何实现这一点。它还将在很大程度上取决于您的应用程序,因为上面将检查id为“target”的元素在拖放之前是否有一个子元素
li
元素,而在拖放之后则没有。如果您有一个HTML源代码的片段,我可能能够证明一个更健壮的示例