doudong7256 2015-06-25 14:45
浏览 77
已采纳

使用同一行中的id单击带有XPath的按钮

Im currently testing using PHPUnit and i need to create and delete the same things. So i create something called test, i want to be able to find it and delete it. I have multiple Delete buttons on the page, and it works by doing something like this -

    $this->click("xpath=(//img[@title='Delete'])[11]");

but by choosing [11] for example, it is only using the delete button from row 11. And if Test isnt Row 11 for example, i will delete something i do not wish to delete.

I wish to try and delete a specific row by finding a row with a certain id attached to it.

The row may have the words "Test" followed by more information within columns. Then a delete button at the end titled 'Delete'. I wish to find the row with the id or words 'Test' and then find and use the 'Delete' title on that row.

Any help?

EDIT -Example image of a row. I would like to grab the first text, and then use the very last button on the right titled 'Delete'

http://i.stack.imgur.com/S4BNE.png

SECOND EDIT - This is the whole table, it contains all of the rows and within the rows it contains the td's (Obviously, as you'd know). This is where ill find the text im trying to find. This tr would count as the 4th of 6.

This shows the td containing delete, a td containing 'Test Profile' and the whole table itself. http://i.imgur.com/4r1tsJe.png

TL;DR Essentially, im trying to do, Where td contains 'Test', use 'Delete' from the same row.

  • 写回答

2条回答 默认 最新

  • douhao2011 2015-06-29 10:35
    关注

    Not very clear but I'll try to guess from your comments.

    Forget about rows, but let's find all the td with "Test" (or some text you want in it)

    descendant::td[contains(.,'Test')]/
    

    and from here select the following-sibling td that contains a delete image

    following-sibling::td//img[@title='Delete']
    

    now you have the set of images nodes to click on, for each row.

    Of course, if your function

    $this->click("xpath=.....");
    

    accepts only one node at the time, one possibility is to put the parenthesis and select always the first node (assuming that your test will delete it)

    (descendant::td[contains(.,'Test')]/following-sibling::td//img[@title='Delete'])[1]
    

    Even if the node is deleted when you click on it, in the next test this expression will always match, until there is any node left on the page

    This is similar (not perfectly the same) to having a for loop ?

    buttons = "xpath=....."
    
    for each b in buttons do {
    
    $this->click(b);
    }
    

    hope it helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题