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")
Mikoupgrade
  • 65
  • 1
  • 9
  • Seems to be in an iframe with ID='iframe_login' so you'll need to switch to the iframe first. See https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python –  May 27 '20 at 14:39
  • @JustinEzequiel thanks for the quick response. However it seems that the URL is not changing, is it not it? – Mikoupgrade May 27 '20 at 14:45
  • Why would the URL change? –  May 27 '20 at 15:00
  • @JustinEzequiel as I understood from your link, the frame is when links of the main page and popup menu are different. Am I right? – Mikoupgrade May 27 '20 at 15:04
  • Odd... the iframe's not there anymore. I must have been looking at some other page. –  May 27 '20 at 15:16

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.

0

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

Mikoupgrade
  • 65
  • 1
  • 9