python输入文字点击按钮,Python Selenium如何单击特定文本旁边的按钮?

Repo1

Delete

Repo2

Delete

Repo3

Delete

In the above code I want to click the Delete button, the problem is that every time a Repo is added, the class name of the repo, the class name of the display text, and the class name of the delete button is all the same for all the repos except for the repo display name.

All I want to do is click the delete button next to a specific repo name.

I tried .//span[text() = "RepoName"] but this only detects the repo name and not the button next to it.

I am pretty new to selenium and I am confused on how to go about it.

解决方案

If you want the button div after a certain RepoX, find the span and get the following div with the Button class:

.xpath("//span[text()='Repo3']/following::div[@class='Button']")

If you did not know the class name but you know it is the next div:

.xpath("//span[text()='Repo3']/following::div[1]")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值