You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IE中.Click事件因onchange异常,网站隐藏标签搜索自动化求助

Hey there, let's tackle these two automation issues one by one—here are actionable solutions tailored to your problems:

1. Fixing .Click Issues in IE Blocked by onchange Events

IE’s event handling is notoriously quirky, especially when onchange and click events interfere with each other. Here are a few reliable workarounds:

  • Explicitly trigger onchange before clicking: If the onchange event is tied to an input value change, fire it manually before triggering the click. For example, using Selenium:
    input_element = driver.find_element(By.ID, "your-input-id")
    input_element.send_keys("new-value")
    # Manually trigger the onchange event
    driver.execute_script("arguments[0].onchange();", input_element)
    # Now execute the click
    click_element = driver.find_element(By.ID, "your-click-target-id")
    click_element.click()
    
  • Simulate native JavaScript events: IE sometimes ignores synthetic events from automation tools. Try dispatching proper change and click events directly via JS:
    // Trigger change event on the input
    const input = document.getElementById('your-input-id');
    const changeEvent = document.createEvent('Event');
    changeEvent.initEvent('change', true, true);
    input.dispatchEvent(changeEvent);
    
    // Trigger click on the target element
    const btn = document.getElementById('your-click-target-id');
    const clickEvent = document.createEvent('Event');
    clickEvent.initEvent('click', true, true);
    btn.dispatchEvent(clickEvent);
    
  • Check for event blocking: Inspect the onchange handler code—if it calls event.preventDefault() or event.stopPropagation(), that could be blocking the click. If you have access to modify the code, remove those lines; if not, bypass the handler via JS execution.
2. Automating the Hidden "Legislação" Tab Search on biblioteca.aneel.gov.br

Let’s break down the steps to interact with this site reliably:

Step 1: Activate the Hidden "Legislação" Tab

The tab is activated via the inline onclick function on the link with id="lk_leg". Automation tools might not trigger this correctly with a simple click, so execute the JS directly:

# Using Selenium as an example
# First, execute the tab activation script
driver.execute_script("move_layer('legislacao', parent.hiddenFrame.layerX);")
# Wait for the tab content to load (critical to avoid race conditions)
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.NAME, "leg_campo1")))

Alternatively, if the script relies on the link’s context, click the element first before executing the JS:

leg_tab = driver.find_element(By.ID, "lk_leg")
leg_tab.click()
# Then add the wait as above

Step 2: Fill the "Todos os campos" Field

Once the tab is active, locate the field by its name attribute and populate it:

search_field = driver.find_element(By.NAME, "leg_campo1")
search_field.clear()  # Clear any pre-filled value
search_field.send_keys("your-search-query")

# Trigger the search (locate the submit button, adjust the selector as needed)
search_btn = driver.find_element(By.XPATH, "//input[@type='submit' or @value='Pesquisar']")
search_btn.click()

Additional Tips for This Site

  • Frame Handling: The site uses a hiddenFrame—if elements aren’t found, check if they’re inside an iframe and switch to it:
    driver.switch_to.frame("hiddenFrame")
    # Perform your actions here
    driver.switch_to.default_content()  # Switch back when done
    
  • Avoid Hard Sleeps: Use explicit waits (like WebDriverWait) instead of time.sleep()—this makes your automation more stable for older, slow-loading sites.

内容的提问来源于stack exchange,提问作者danieltakeshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:36:04