How to click a checkbox when another obscure element is it?

Asked

Viewed 82 times

0

I’m writing a code to automate some processes on the SIAFI site, I couldn’t get Python to click on a checkbox, except by importing the package pynput and using the mouse positioning function with the coordinates (x, y):

from pynput.mouse import Button, Controller
mouse = Controller()

After I imported I used the code below to click exactly on this location:

mouse.position (121,278)

The problem is that if I use this script on a different monitor, I have to modify the coordinates (x,y). I wanted Python to recognize the field of checkbox and click on it, regardless of the coordinates.

elemento11 = wait.until(EC.element_to_be_clickable((By.ID, 'formComp:tabelaPesquisarCompromissos:marcaTodas')))
elemento11 = browser.find_element_by_id('formComp:tabelaPesquisarCompromissos:marcaTodas')
mouse.position = (121, 278)#levar o mouse até a posição DEPENDENDO SE A PÁGINA FOR A ÚLTIMA PODE VARIAR
mouse.click(Button.left, 1)#clicar em selecionar todas
elemento12 = wait.until(EC.element_to_be_clickable((By.ID, 'formComp:botao_marcar_opcao_realizacao')))
time.sleep(int(segundos))

Below I will describe the html code of the siafi web page:

<input id="formComp:tabelaPesquisarCompromissos:marcaTodas" name="formComp:tabelaPesquisarCompromissos:marcaTodas" onclick="selecionarTodos(this);" type="checkbox">

1 answer

0

It’s unclear to me why you can’t click this checkbox. It’s because it’s hidden or because it only appears based on other checkboxes?

One solution that the QA team found in my work, was to create a method that keeps checking if the element is visible, to then execute something.

Something like (I’m writing from my head, I don’t know if it works):

def esperar_por_elemento():
    tentativas = 0
    while tentativas < limite_de_tentativas:
    if browser.find_element_by_id()
        break
    sleep(ALGUM_TEMPO_PRA_ESPERAR)
    tentativas += 1
    return browser.find_element_by_id()

The idea is more or less this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.