3 回答

TA贡献1775条经验 获得超11个赞
该文本框和按钮元素内的<iframe>,所以你必须:
Induce WebDriverWait等待所需的框架可用并切换到它。
Induce WebDriverWait使所需元素可点击。
您可以使用以下解决方案:
代码块:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("http://www.dsv.de/schwimmen/wettkampf-national/schwimmerabfrage/")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[@src='https://dsvdaten.dsv.de/Modules/Results/Individual.aspx?Lang=de-DE']")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='TextBox' and @id='_firstnameTextBox']"))).send_keys("juliu_mbr")
driver.find_element_by_xpath("//input[@class='TextBox' and @id='_lastnameTextBox']").send_keys("juliu_mbr")
driver.find_element_by_xpath("//input[@class='Button' and @id='_submitButton']").click()
浏览器快照:
在这里你可以找到关于Ways to deal with #document under iframe的相关讨论

TA贡献1789条经验 获得超8个赞
all部分在<iframe>标签里面,你需要先切换到它
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, 5)
wait.until(ec.frame_to_be_available_and_switch_to_it((By.TAG_NAME, 'iframe')))
submit_button = driver.find_element_by_name("_submitButton")
#...

TA贡献1804条经验 获得超7个赞
您需要切换到框架,然后定位元素
url = "http://www.dsv.de/schwimmen/wettkampf-national/schwimmerabfrage/"
driver = webdriver.Chrome()
driver.get(url)
driver.switch_to.frame(driver.find_element_by_xpath('//iframe[@src='https://dsvdaten.dsv.de/Modules/Results/Individual.aspx?Lang=de-DE']'));
// then your code for the Login
submit_button = driver.find_element_by_name("_submitButton")
fistname_textbox = driver.find_element_by_xpath('//*[@id="_firstnameTextBox"]')
lastname_textbox = driver.find_element_by_xpath('//*[@id="_lastnameTextBox"]')
regid_textbox = driver.find_element_by_id("_regidTextBox")
fistname_textbox.send_Keys("String 1")
lastname_textbox.send_keys("String 2")
submit_button.click()
driver.close()
添加回答
举报