我要简化https://www.trademap.org/Index.aspx网站。如果我单击登录按钮,将出现一个小的弹出式登录。但是,ID列表不包括此小窗口。例如,我试图等到“登录”按钮变为可用时,不幸的是导致无法找到元素(我也使时间入睡)。我如何在这个小窗口中访问ID
我尝试过:
#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")
答案 0 :(得分:0)
我知道某处有一个iframe。见下文。
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()
我确定您可以从这里拿走它。
答案 1 :(得分:0)
WebDriverWait(驱动程序,10).until(EC.frame_to_be_available_and_switch_to_it(“ iframe_login”))