我正在尝试SeleniumWebdriver按名称查找输入元素并输入一个值



我正试图在最后一个框中输入一个值。(Numéro de châssis(

我试过:

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
URL_BASE = "https://www.mobilit.fgov.be/WebdivPub_FR/wmvpstv1_fr?SUBSESSIONID=16382865"
browser = webdriver.Chrome(executable_path=ChromeDriverManager().install())
browser.get(URL_BASE)  
input_1 = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='Writable3']")))
input_1.send_keys("ABCD")

我收到这个错误

File ~anaconda3libsite-packagesseleniumwebdriversupportwait.py:90 in until
raise TimeoutException(message, screen, stacktrace)
TimeoutException

HTML:

<input type="TEXT" autocomplete="off" class="DFGUISLE Writable3" name="Writable3" id="Writable3" maxlength="17" style="dir:ltr;   position:absolute; left:416; top:446; width:235; height:22;  ">
您试图访问的元素在iframe中。您首先需要切换到该iframe才能访问其中的元素。
这对我很有效:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:webdriverschromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)
url = 'https://www.mobilit.fgov.be/WebdivPub_FR/wmvpstv1_fr?SUBSESSIONID=16382865'
driver.get(url)
wait = WebDriverWait(driver, 20)
wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element(By.CSS_SELECTOR, "[name='AppWindow']")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='Writable3']"))).click()

当你在iframe内完成工作时,不要忘记使用返回默认内容

driver.switch_to.default_content()

相关内容

  • 没有找到相关文章

最新更新