0

I cannot click on the button but every method I tried has failed. Here is the result of clicking "inspect" in chrome:

<button class="rg-run-report-button md-raised md-primary md-ink-ripple md-button" type="submit" ng-transclude="" ng-click="reportCtrl.generateReport()" ng-disabled="!(reportCtrl.isGenerateButtonEnabled())">
        RUN REPORT
      <div class="md-ripple-container" style=""></div></button>

I am going off of this and building an Xpath like this:

driver.find_element_by_xpath("//button[contains(text(), 'RUN REPORT')]").click()

The text "RUN REPORT" has a lot of awkward whitespace around it. I am not sure what to do since I have tried to locate the button via its attributes.

Sarah
  • 3
  • 4

2 Answers2

1

Try one of following locators - following locator will remove spaces around the text and look for text only

//button[normalize-space(text()='RUN REPORT')]

or from the html structure it seems your application is angular for application developed in angular using ng tags is quite effective

//button[@ng-click="reportCtrl.generateReport()"]
Dev
  • 2,739
  • 2
  • 21
  • 34
  • I got a NoSuchElement exception when I tried both. I am not sure what else to try. Thank you! @Dev – Sarah Jul 22 '19 at 16:42
  • use wait condition before checking for element and check if element is inside frame, if yes then you need to select frame first – Dev Jul 22 '19 at 19:21
  • I am using a wait right now, but what do you mean by "select frame first" and how would you go about doing that? When I watch the driver's actions the page that the button is on is loaded before the clicking action. – Sarah Jul 22 '19 at 20:11
  • there are iframes on webpage which are hidden and cant see by open eyes manytimes , if web elements are inside iframe we need to select iframes first then look for elements inside iframes – Dev Jul 22 '19 at 20:14
  • how would you select iframes? – Sarah Jul 22 '19 at 20:21
  • here you go - https://stackoverflow.com/q/18366689/5400362 and for better understanding - read this thread - https://www.guru99.com/handling-iframes-selenium.html – Dev Jul 22 '19 at 20:24
  • I appreciate it! Thank you! – Sarah Jul 22 '19 at 20:25
  • 1
    I did as you suggested and hunted around a bit to find the right iframe. It worked! I used the ng-click example you gave for the Xpath and it worked too! THANK YOU – Sarah Jul 22 '19 at 22:52
0

Thank you to @Dev:

The issue with finding the element that I needed to click was not from an incorrect Xpath locator, but not thinking to switch iframes. The source that I was looking at did not contain the element directly, but did have one iframe (out of two total) that did.

When I clicked "inspect element" on the button, it didn't show me the components directly. BECAUSE the components were nested in an iframe.

I did:

driver.switch_to.frame('name of iframe')

THEN

driver.find_element_by_xpath("//button[@ng-click='reportCtrl.generateReport()']")
Sarah
  • 3
  • 4