0

I am going to scrape the https://www.trademap.org/Index.aspx website. If I click the login button the small popup login will appear. However, list of ID does not include this small window. For example, I tried to wait until "LOG IN" button becomes available, unfortunately resulting in Unable to locate element (i put time to sleep also). How can I get access to ID in this small window enter image description here

I tried:

#WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "PageContent_Login1_Button")))


#driver.find_element_by_id('PageContent_Login1_UserName').send_keys(username)
#driver.find_element_by_id('PageContent_Login1_Password').send_keys(password)


driver.find_element_by_name('ctl00$PageContent$Login1_UserName').send_keys("my_first_name")

2 Answers2

0

I knew there was an iframe somewhere. See below.

import time

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

driver = webdriver.Chrome()
driver.get('https://www.trademap.org/Index.aspx')

wait = WebDriverWait(driver, 10)

# click login button
e = wait.until(EC.element_to_be_clickable(
    (By.ID, 'ctl00_MenuControl_Label_Login')))
e.click()

time.sleep(5)

# switch to iframe
wait.until(
    EC.frame_to_be_available_and_switch_to_it((By.ID, 'iframe_login')))

# fill in username
e = wait.until(EC.visibility_of_element_located(
    (By.ID, 'PageContent_Login1_UserName')))
e.clear()
e.send_keys('justin@was.here')

time.sleep(5)

# back to main document
driver.switch_to.default_content()

# close popup
e = wait.until(EC.element_to_be_clickable(
    (By.ID, 'ctl00_MenuControl_Button_ClosePopupLogin')))
e.click()

time.sleep(5)

driver.quit()

I'm sure you can take it from here.

Justin Ezequiel
  • 5,254
  • 2
  • 11
  • 14
0

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it("iframe_login"))