0

I want to show more page by click a button to run a JavaScript function as below:

<div class="loading" style="display:none;">
  <p class="btn blue"><span>さらに表示</span></p>
  <a href="javascript:void(0);" onclick="get_more();"></a>
</div>

I tried the code, it doesn't work, what can I do?

more_info_button = driver.find_element_by_tag_name('a').get('href=javascript:void(0);')
more_info_button.click() 
1
  • Try using xpath //div/a[contains(@onclick,'get_more')] Commented Aug 17, 2018 at 9:01

1 Answer 1

1

If you want to click link that contains attribute @href equal to "javascript:void(0);", try

more_info_button = driver.find_element_by_xpath('//a[@href="javascript:void(0);"]')
more_info_button.click() 

Same with CSS selector:

more_info_button = driver.find_element_by_css_selector('a[href="javascript:void(0);"]')

To locate link by text in preceding paragraph:

more_info_button = driver.find_element_by_xpath('//a[preceding-sibling::p[.="さらに表示"]]')

Update

Try below code to get extended topics list after clicking the button:

from selenium.webdriver.support.ui import WebDriverWait

topics_number = len(driver.find_elements_by_class_name('topics'))
more_info_button.click()
WebDriverWait(driver, 10).until(lambda driver: len(driver.find_elements_by_class_name('topics')) > topics_number)
extended_list = driver.find_elements_by_class_name('topics')
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks, How can I check if page is full loaded after click?
What exactly you want to do next after click?
After click button, all rest contents will be extended to show in the same page, I want to parse it after page finishing loaded.
You might need to implement ExplicitWait to wait for new element to be present in DOM/to be visible...
I am not sure why I got the same result even f the button is clicked. I tried to parse this page https://weathernews.jp/s/topics/, the 'more' button is at the bottom of page, can you help me?
|

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.