0

Using Selenium to try and locate + press a button inside of an Atlassian Jira environment.

![Image](https://ibb.co/T4Dr87h)

The button class is not unique and the button doesn't have a button ID. I assume the website is built in an incompatible way to interact with Selenium. All attempts end with no elements found. Has anyone got any suggestions?

I'm using PowerShell currently and have tired numerous search methods here's the latest which I hoped would work but still nothing..

# Find the <span> element with the text "Update site"
$span_element = $driver.FindElementByXPath("//span[text()='Update site']")

# Navigate to its parent <button> element
$button_element = $span_element.FindElementByXPath("./..")

# Perform actions on the button
$button_element.Click()

1 Answer 1

0

One way is to look for all buttons and then filter out the button which has a span with the text you want.

E.g.

# Find all buttons on the page
$allButtons = $driver.FindElementsByTagName("button")

# Filter the button with a span element containing "Update site"
$updateButton = $null
foreach ($button in $allButtons) {
    try {
        # Check if the button has a span with the specified text
        $span = $button.FindElementByXPath(".//span[text()='Update site']")
        if ($span -ne $null) {
            # If found, set $updateButton to this button
            $updateButton = $button
            break
        }
    } catch {
        # If an exception is raised, it means this button doesn't have the desired span
    }
}

if ($updateButton -ne $null) {
    # If the desired button is found, click it
    $updateButton.Click()
} else {
    Write-Host "No button with 'Update site' found"
}

Or you can do it in one search:

$updateButton = $driver.FindElementByXPath("//button[span[text()='Update site']]")
2
  • Thanks for the suggestion. I've tried the XPath search by name and get the same "Not found." result. Both your suggestions return no results as its cant find the button object. Commented Apr 25 at 13:24
  • @MatthewGosnell Are you sure the button is visible? One way to detect this is to search each level of indentation until you find an error. You do find #root and put in an variable. Then you search in this variable for a div and put in another variable. So on and so forth.. The error will be throw on the exact element that is problematic, e.g. div.rightOptions. Commented Apr 26 at 10:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.