Imagine a kanban board UI
to do | inprogress | done
task1 task1 task1
task2 task2 task2
task3 task3 task3
task4 task4 task4
task5 task5 task5
DOM of kanban board:
//--Start--
<iframe id = 'ardafder2312'>
<div class = 'container'>
<div class = 'todo'>
<div class = 'card-title' text='task1'>
<div class = 'card-title' text='task2'>
<div class = 'card-title' text='task3'>
<div class = 'card-title' text='task4'>
<div class = 'card-title' text='task5'>
</div>
<div class = 'inprogress'>
<div class = 'card-title' text='task1'>
<div class = 'card-title' text='task2'>
<div class = 'card-title' text='task3'>
<div class = 'card-title' text='task4'>
<div class = 'card-title' text='task5'>
</div>
<div class = 'done'>
<div class = 'card-title' text='task1'>
<div class = 'card-title' text='task2'>
<div class = 'card-title' text='task3'>
<div class = 'card-title' text='task4'>
<div class = 'card-title' text='task5'>
</div>
</iframe>
//--End--
//以下代码段有效
switchto(iframe)
WebElement container = driver.findelement(by_xpath("//*[contains(@class,'container')]//*[contains(@class,'todo')]//*[text(),'task1']").click());
要求是使用动态功能单击“完成”列下的“任务5” ,我希望使用Sikuli中的区域进行概念搜索来实现。在其中找到父项并搜索子项。
因此,在下面创建了一个函数,我们在其中标识父级Web元素并在其中搜索子级Web元素。
请告诉我这是否可行或需要进行任何更改。
function test(String state, String taskName)
{
WebElement container = driver.findelement(by_xpath("//*[contains(@class,'container')]//*[contains(@class,'"+state+"')]")); //trying to create a region - parent
WebElement task = container.findelement(by_xpath("//*[text(),'task1']")) //trying to search within the container - child of above parent
}
test("done", "task1")
结果:
预期结果:用户应该单击“完成”列下可用的“任务1”
实际结果(问题):单击“待办事项”列下可用的“任务1”。
答案 0 :(得分:1)
更改
WebElement task = container.findelement(by_xpath("//*[text(),'task1']"))
到
WebElement task = container.findelement(by_xpath(".//*[text(),'task1']"))
.
表示您从当前节点开始