Repo1
Repo2
Repo3
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]”)