0

I'm pretty new to using python in selenium.

I have been trying to select a button on my web page. Here is the piece of HTML that appears after inspecting the element of the button:

<a class="btn col-xs-3 nav-btns" ui-sref="salt.dashboard.reports.minions" href="/dashboard/reports/minions/">

    <span class="ssIcons-icon_reports salt-icon-3x ng-scope active" bs-tooltip="" data-title="Reports" container="body" placement="bottom" animation="none" data-trigger="hover" ng-class="{'active': state.current.name =='salt.dashboard.reports' … || state.current.name =='salt.dashboard.reports.minions'}">

    ::before
    </span>

</a>

I have tried everything I can think of. Here are some of the things that I have tried:

element = driver.find_element_by_class_name("btncol-xs-3")
element = driver.find_element_by_name("Reports")
element = driver.find_element_by_id("Reports")

the error that I keep getting is:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"class name","selector":"salt.dashboard.reports"} Stacktrace: at FirefoxDriver.prototype.findElementInternal_ (file:///tmp/tmpoRPJXA/extensions/[email protected]/components/driver-component.js:10299) at FirefoxDriver.prototype.findElement (file:///tmp/tmpoRPJXA/extensions/[email protected]/components/driver-component.js:10308) at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmpoRPJXA/extensions/[email protected]/components/command-processor.js:12282) at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmpoRPJXA/extensions/[email protected]/components/command-processor.js:12287) at DelayedCommand.prototype.execute/< (file:///tmp/tmpoRPJXA/extensions/[email protected]/components/command-processor.js:12229) root@chris-salt:/home/chris/Documents/projects/python-selenium#

2 Answers 2

1

Find the element by data-title:

driver.find_element_by_css_selector("span[data-title=Reports]")

Or, if you need to get to the a tag:

driver.find_element_by_xpath("//a[span/@data-title = 'Reports']")
Sign up to request clarification or add additional context in comments.

1 Comment

driver.find_element_by_css_selector("span[data-title=Reports]") did the trick. I was trying to use the data-title before I just didn't have the correct format. Thanks a lot!
0

Chris,

The span that you pasted doesn't has an attribute named id.

Also, your class selector is too wide, i'd suggest using a more explicit path following the dom structure. Bare in mind that there may be multiple elements that have that class name.

Also, you are trying to find by the attribute name, which you don't have in that element.

Finally, it seems that you might be using angular. Does the input that you are looking for is created with javascript dinamically ?

And also, why are you using root to do this tests ?

Before doing the asserts, can you store the resulting html and manually checking that you indeed have that element?.

2 Comments

I realize that there is not a name or an id attribute, it was just something that I tried... :/
I am just trying to figure out how to click the button. I can find and click other buttons on the page, just not a few that are on the top (almost like tabs)

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.