0

selenium can't locate the element. The error info:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"loadAllUpcomingPast"}

my code is:

url_base = 'http://www.christies.com/lotfinder/searchresults.aspx&searchtype=p&action=paging&searchFrom=header&lid=1&entry=&pg=all'

driver = webdriver.Chrome()

driver.get(url_base)

time.sleep(2)

driver.switch_to.frame("signupFrame")

driver.find_element_by_id("close_signup").click()

time.sleep(2)
driver.find_element_by_id("loadAllUpcomingPast").click()

the screenshot

enter image description here

hoefling
  • 59,418
  • 12
  • 147
  • 194
  • I cannot browse http://www.christies.com/lotfinder/searchresults.aspx&searchtype=p&action=paging&searchFrom=header&lid=1&entry=&pg=all – Nabin Nov 22 '17 at 16:13
  • the whole url is http://www.christies.com/lotfinder/searchresults.aspx?&searchtype=p&action=paging&searchFrom=header&lid=1&entry=lama&pg=all – Goodmanyeahhh Nov 22 '17 at 16:14
  • Still cannot that – Nabin Nov 22 '17 at 16:14
  • The correct url should be [this](http://www.christies.com/lotfinder/searchresults.aspx?searchtype=p&action=paging&searchFrom=header&lid=1&entry=&pg=all) – hoefling Nov 22 '17 at 16:15
  • https://stackoverflow.com/questions/7781792/selenium-waitforelement – Nabin Nov 22 '17 at 16:15
  • http://www.christies.com/lotfinder/searchresults.aspx?&searchtype=p&action=paging&searchFrom=header&lid=1&entry=lama&pg=all – Goodmanyeahhh Nov 22 '17 at 16:16

1 Answers1

0

Seems that the loadAllUpcomingPast gets loaded later on. You could try something like this:

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


url_base = 'http://www.christies.com/lotfinder/searchresults.aspx?&searchtype=p&action=paging&searchFrom=header&lid=1&entry=lama&pg=all'
driver = webdriver.Chrome()
driver.get(url_base)

wait = WebDriverWait(driver, 5)

try:
    element = wait.until(EC.element_to_be_clickable((By.ID, 'loadAllUpcomingPast')))
    print(f'Element found: {element}')
except TimeoutException:
    print('could not find loadAllUpcomingPast')

In my console I see:

Element found: <selenium.webdriver.remote.webelement.WebElement (session="c9f1b83164f34001aa0a98581618d45b", element="0.6182317130585246-1")>

This will tell Selenium to wait until that element is clickable. You can adjust the wait time if needed within the WebDriverWait 2nd argument.

kstullich
  • 651
  • 1
  • 11
  • 27
  • it seems something wrong, element = wait.until(EC.element_to_be_clickable(By.ID, 'loadAllUpcomingPast')) TypeError: __init__() takes 2 positional arguments but 3 were given – Goodmanyeahhh Nov 22 '17 at 16:25
  • I adjust time to 30, still can't locate the element.thx buddy! appreciate for your help! – Goodmanyeahhh Nov 22 '17 at 16:54
  • @Goodmanyeahhh it works for me. I edited the post with a print statement and it shows me the element. Unsure as to why it does not work for you. – kstullich Nov 22 '17 at 17:02
  • when open the page, a registration window appeared.so I used the code:"driver.switch_to.frame("signupFrame") driver.find_element_by_id("close_signup").click()" to close the window,and then click the load all button.Could the problem be here? – Goodmanyeahhh Nov 23 '17 at 05:56
  • the code is work, I change new network, it works! thanks! – Goodmanyeahhh Dec 05 '17 at 07:55