2

I'm working in selenium with Chrome. The webpage I'm accessing updates dynamically. I need the html that shows the results, I can access it when I do 'inspect element'. I don't get how I need to access that html from my code. I always get the original html.

I tried this: Get HTML Source of WebElement in Selenium WebDriver using Python

browser.get('http://bijsluiters.fagg-afmps.be/?localeValue=nl')
searchform = browser.find_element_by_class_name('iceInpTxt')
searchform.send_keys('cefuroxim')
button = browser.find_element_by_class_name('iceCmdBtn').click()

element = browser.find_element_by_class_name('contentContainer')
html = element.get_attribute('innerHTML')
browser.close()
print(html)

1 Answer 1

1

It seems that it's working after some delay. If I were you I should try to experiment with the delay time.

from selenium import webdriver
import time

browser = webdriver.Chrome()

browser.get('http://bijsluiters.fagg-afmps.be/?localeValue=nl')
searchform = browser.find_element_by_class_name('iceInpTxt')
searchform.send_keys('cefuroxim')
button = browser.find_element_by_class_name('iceCmdBtn').click()

time.sleep(10)

element = browser.find_element_by_class_name('contentContainer')
html = element.get_attribute('innerHTML')
browser.close()
print(html)

Addition: a nicer way is to let the script proceed when an element is available (because of time it takes with JS (for example) before a specific element has been added to the DOM). The element to look for in your example is table with id iceDatTbl (for what I could find after a quick look).

Sign up to request clarification or add additional context in comments.

1 Comment

You're right, it works. Now I feel stupid, I tried this before but only with a delay of 1 second because I saw instant results when I did it manually. Thanks.

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.