0
votes

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

2 Answers

1
votes

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']")
0
votes

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?.