1
<div class = "Repo List">
    <div class = "Repo">
        <div class = "Text">
            <span class = "Display Text">Repo1</span>
        </div>
        <div class = "Button">
            <div class = "Click Button">Delete</div>
        </div>
    </div>

    <div class = "Repo">
        <div class = "Text">
            <span class = "Display Text">Repo2</span>
        </div>
        <div class = "Button">
            <div class = "Click Button">Delete</div>
        </div>
    </div>

    <div class = "Repo">
        <div class = "Text">
            <span class = "Display Text">Repo3</span>
        </div>
        <div class = "Button">
            <div class = "Click Button">Delete</div>
        </div>
    </div>
</div>

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.

2 Answers 2

1

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]")
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly when used './/span[text()="'+Name+'"]/following::div[@class="Button"]' for xpath.
No worries, you can use also str.format './/span[text()="{}"]/following::div[@class="Button"]'.format(s)
0

To click the "Delete" button just after the "Repo1" text:

driver.find_element_by_xpath("//span[.='Repo1']/following::div[.='Delete'][1]").click()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.