[英]Python Selenium trying to click button not working
I'm trying to click in a button by using CSS Selector.我正在尝试使用 CSS 选择器单击按钮。 I've tried by using input with value, title and onclick but not working, this is html code :我尝试使用带有值、标题和 onclick 的输入,但不起作用,这是html 代码:
<div id="botaoMarcar"><input type="button" disabled class="botao"
value="Marcar todas" title="Marcar todas" onclick="javascript:marcarDesmarcarTodos(true);"
></div>
My code:我的代码:
driver = Chrome()
url = "https://www3.bcb.gov.br/sgspub/localizarseries/localizarSeries.do?method=prepararTelaLocalizarSeries"
driver.get(url)
try:
WebDriverWait(driver, 3).until(EC.alert_is_present(),
'Timed out waiting for PA creation ' + 'confirmation popup to appear.')
alert = driver.switch_to.alert
alert.accept()
except TimeoutException:
print("No Alert")
driver.implicitly_wait(5)
driver.maximize_window()
# This part is for input table code that I want to access
id_code = driver.find_element(By.ID, 'txCodigo')
id_code.send_keys(24)
id_code.send_keys(Keys.ENTER)
# Part not working exactly
clic_code = driver.find_element(By.CSS_SELECTOR, 'input[value*="Marcar todas"]')
clic_code.click()
Your element is in an iframe.您的元素位于 iframe 中。
<iframe id="iCorpo" name="iCorpo" align="center" marginwidth="0" marginheight="0" src="localizarSeries.do?method=recuperarGruposPrincipais" frameborder="0" width="100%" scrolling="auto" height="280" style="height: 399.36px;"></iframe>
Simply wait and switch to it prior to finding that element.只需等待并在找到该元素之前切换到它。
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"#iCorpo")))
Import:进口:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.