1

I am trying to extract some data from a site which loads the data using ajax and I am using selenium along with python for this.I want to click on a link which appears after an ajax page load. I have even put sleep function of python so that the page loads completely, but still not able to click. This error comes every time "selenium.common.exceptions.NoSuchElementException: Message: no such element".Please see the following code which I have written. Thanks

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import time
import subprocess
from selenium.webdriver.chrome.options import Options

chromeOptions = webdriver.ChromeOptions()
prefs = {"download.default_directory" : "C:/Users/212553509/Desktop/WHO"}
chromeOptions.add_experimental_option("prefs",prefs)
chromedriver = "C:/python27/Scripts/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)
driver.get("http://apps.who.int/gho/data/node.home")
time.sleep(20)
driver.find_element_by_link_text('node.main.484?lang=en').click()

2 Answers 2

1

You need to use a WebDriverWait so that Selenium has a chance to repeatedly poll the page to look for your element:

http://selenium-python.readthedocs.org/waits.html

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

1 Comment

Thanks.. but the wait isn't working either. The table is not visible on the source code itself.
0

You are passing the link href, not the link text to driver.find_element_by_link_text. If you have HTML code like this

<a target="_top" href="node.main.MEDSMDG8?lang=en">Essential medicines</a>

Use driver.find_element_by_text('Essential medicines')

2 Comments

Thanks! but I tried this also. can you suggest any other libraries using which I can fetch the data which is visible on the page but not in the source code
You can try scraperJs - I find it a lot easier to use compared to Python + Selenium.

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.