0

I am trying to click a button with Selenium Web Driver.

(I think it is written in Angular??)

URL is https://www.truelocal.com.au/search/accountants/canberra

It's the green button at bottom of page with "Load More Results"

Element page source is ...

<button class="btn btn-full btn-add js-review-open" ng-class="{true:'btn-loading', false:''}[vm.loadingMore]" ng-hide="vm.checkResultsOffset()" ng-click="vm.loadMoreResults()" aria-hidden="false" style="">

  <!-- ngIf: vm.loadingMore==true -->
  <!-- ngIf: vm.loadingMore==false -->
  <span ng-if="vm.loadingMore==false" class="ng-scope" style="">LOAD MORE RESULTS</span>
  <!-- end ngIf: vm.loadingMore==false -->
</button>

The only thing I can really do is

elm = driver.find_elements_by_xpath("//*[contains(text(), 'LOAD MORE RESULTS')]")

But I can't get the button to click.

Any help please?

1
  • are you getting any relevant stack trace which shows why the test is failing? Commented Nov 27, 2017 at 11:35

2 Answers 2

1

Try this. It will keep clicking on the load more button until there is no such button is left to be clicked.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get("https://www.truelocal.com.au/search/accountants/canberra")
wait = WebDriverWait(driver, 10)

while True:
    try:
        link = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button[ng-click='vm.loadMoreResults()'] .ng-scope")))
        link.click()
        wait.until(EC.staleness_of(link))
    except:
        break
driver.quit()
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I appreciate your help @Shahin
0

To click the button with text LOAD MORE RESULTS we have to wait for the button to render properly as the button is an Angular Element. So you can use the following code block :

WebDriverWait(driver, 10).until(EC.text_to_be_present_in_element(By.XPATH,"//button[@class='btn btn-full btn-add js-review-open']/span[@class='ng-scope']"),'LOAD MORE RESULTS')
driver.find_elements_by_xpath("//button[@class='btn btn-full btn-add js-review-open']/span[@class='ng-scope']").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.