无头Firefox点击Normale Suche后在handelsregister.de遇Selenium NoSuchElementError
无头Firefox模式下Selenium无法定位表单元素的问题
我使用无头模式的Firefox Selenium自动化操作https://www.handelsregister.de/rp_web/welcome.xhtml进行文档搜索。脚本能成功加载页面并点击"Normale Suche"按钮,但填充表单时失败,报错信息如下:
NoSuchElementError: Unable to locate element:
/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/form/div[3]/div[2]/textarea
我已通过浏览器开发者工具确认该XPath有效,且相同代码在非无头模式下可正常运行。
已尝试的操作:
- 使用WebDriverWait等待页面和表单加载完成
- 手动验证XPath的有效性
- 对比无头与非无头模式的测试结果(仅非无头模式可用)
预期行为:点击"Normale Suche"后,输入字段应显示并可填充内容,但无头模式下Selenium无法找到这些元素。
代码片段:
driver.get("https://www.handelsregister.de/rp_web/welcome.xhtml") wait.until(EC.presence_of_element_located((By.TAG_NAME, "body"))) driver.find_element(By.ID, "naviForm:normaleSucheLink").click() wait.until(EC.presence_of_element_located((By.ID, "mainForm"))) driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/form/div[3]/div[2]/textarea").send_keys("WGO Grundstücks GmbH")
内容的提问来源于stack exchange,提问作者Vaibhavi K
相关产品推荐
相关产品推荐

