1

I have the below element on a webpage I am trying to scrape.

<a href="http://www.mylink/?p=20391">Sup Bonds Result June 26, 2018</a>

Below is the code that I am trying to use but doesn't seem to be working although the value exists. It worked for initial few instances but then isn't providing any result.

try:
    element=driver.find_element_by_partial_text('Sup Bonds Result June 26, 2018')

except NoSuchElementException:
    driver.quit()

below is the error that i Received, I have already used the time.sleep o allow sometime for the script to locate the element.

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Sup Bonds Result June 26, 2018"}

Any help is appreciated.

2 Answers 2

1

Try to apply ExplicitWait as below:

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

try: 
    wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Sup Bonds Result June 26, 2018")))
except TimeoutException:
    driver.quit()

Also note that if you want to use search by link text (partial link text) you need to pass text exactly as it appears on page in browser, but not as it appears in page source. So if it looks on page like "SUP BONDS..." you need to use the same in code

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

1 Comment

Thanks Anderson for the help.. Works perfectly fine.
1

Seems you were pretty close. As you are simply trying to locate (not clicking) the element, you need to induce WebDriverWait for the visibility of the element as follows:

try:
    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.PARTIAL_LINK_TEXT, "Sup Bonds Result June 26, 2018"))).click()
except TimeoutException:
    driver.quit()

Note : You have to add the following imports :

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

1 Comment

Thanks Debanjan... This works as well but am unable to mark two answers.

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.