Leandro de Sant'Anna Knorre

All generations.

generate functionTue, 10 Jan 2023

click all checkboxes with ids like ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl01_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl02_chkDataJornalItem, and so on, all the way to ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl99_chkDataJornalItem, stopping when a checkbox with a given number is not found

# click checkboxes def click_checkboxes(driver, cb_id, until): base_id = "ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl" for i in range(until): if i < 10: id = base_id + "0" + str(i) + cb_id else: id = base_id + str(i) + cb_id try: id_elem = driver.find_element_by_id(id) id_elem.click() except NoSuchElementException: print("checkbox not found") return click_checkboxes(driver, "_chkDataJornalItem", 10)

Python
View
generate functionWed, 11 Jan 2023

click all checkboxes with ids like ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl01_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl02_chkDataJornalItem, and so on, all the way to ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl99_chkDataJornalItem, stopping when a checkbox with a given number is not found

def click_checkboxes(start, end): i = start while True: try: browser.find_element_by_id("ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl%02d_chkDataJornalItem" % i).click() i = i + 1 except: print("Done with %d" % (i - 1)) break click_checkboxes(0, 99)

Python
View
generate functionWed, 11 Jan 2023

clicar no elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar" passe o mouse sobre o elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" clicar em <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

def download(driver): # Clicar no link "Exportar" driver.find_element_by_id("ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar").click() # Clicar no link "Planilha" driver.find_element_by_link_text("Planilha").send_keys(Keys.ENTER)

Python
View
generate functionTue, 10 Jan 2023

click all checkboxes in elements similar to the following two: <label class="container-label"> <input id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem" type="checkbox" name="ctl00$ContentPlaceHolder1$dtlDataJornalPublicacao$ctl00$chkDataJornalItem"> <span class="checkmark"></span> </label> <label class="container-label"> <input id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl01_chkDataJornalItem" type="checkbox" name="ctl00$ContentPlaceHolder1$dtlDataJornalPublicacao$ctl01$chkDataJornalItem"> <span class="checkmark"></span> </label>

def check_box_click(id_string, driver): box_to_click = driver.find_element_by_id(id_string) box_to_click.click() check_box_click("ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem", driver)

Python
View
code to explanationWed, 18 Jan 2023

function onEdit(e) { var sheet = e.source.getActiveSheet(); if (sheet.getName() == 'Sheet1' && e.range.getColumn() == 16) { var selection = e.range.getValue(); if (selection !== '') { var cellToChange = sheet.getRange(e.range.getRow(), e.range.getColumn() - 1); if (cellToChange.getValue() !== "cadastrada") { cellToChange.setValue('peticionar'); } } } }

This function is executed when a user makes a modification in a cell in the sheet Sheet1. The function gets the current sheet and checks if the columns is 16. If it is, it checks if the value of the cell is different from an empty string. If it isn't, it gets the sheet, the row and the column of the cell, and checks if the value of the cell is different from cadastrada. If it is, it sets the cell value to peticionar.

generate functionWed, 11 Jan 2023

clicar em <div id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar"> mouse over <div id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" class="popup_menu" style="visibility: hidden; position: absolute; left: 286px; top: 6347px; z-index: 1000; display: none;"> clicar em <td style="white-space:nowrap;width:100%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By def open_driver(): options = webdriver.ChromeOptions() options.add_argument('--headless') #options.add_argument('--no-sandbox') #options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver',chrome_options=options) return driver def export_to_xls(driver, url): driver.get(url) #wait = WebDriverWait(driver, 10) #export_button = driver.find_element_by_id("ctl00_ContentPlaceHolder1_List

Python
View
generate functionWed, 11 Jan 2023

clicar no elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar" mouse over elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" clicar em <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

def mouse_over_click(a, b): element = driver.find_element_by_id(a) element.click() element = driver.find_element_by_id(b) element.click() def click_by_href(a): driver.find_element_by_xpath("//a[@href='"+a+"']").click() mouse_over_click("ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar", "ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao") mouse_over_click("javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')", "style")

Python
View
generate functionWed, 11 Jan 2023

clicar no elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar" passe o mouse sobre o elemento com id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" clicar em <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re class AppDynamicsJob(unittest.TestCase): def setUp(self): # AppDynamics will automatically override this web driver # as documented in https://docs.appdynamics.com/display/PRO44/Write+Your+First+Script self.driver = webdriver.Chrome('/opt/google/chrome/chromedriver') self.driver.implicitly_wait(30) self.base_url = "https://www.katalon.com/" self.verificationErrors = [] self.accept_next_alert = True

Python
View
code to explanationWed, 18 Jan 2023

function onEdit(e) { var sheet = e.source.getActiveSheet(); if (sheet.getName() == 'Sheet1' && e.range.getColumn() == 1) { var selection = e.range.getValue(); if (selection == 'Selecione uma opção') { var cellToChange = sheet.getRange(e.range.getRow(), e.range.getColumn() - 1); cellToChange.setValue('peticionar'); } } }

The function onEdit is run automatically whenever a cell is edited. The script checks if the sheet name is Sheet1 and the column is column A. It then gets the current selection and if it is "Selecione uma opção", it deletes the content in the cell one column to the left.

generate functionTue, 17 Jan 2023

improve the following function so it compares columns A:K of the row, and when it is duplicate, it removes the whole row function removerDuplicatas() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var lastRow = sheet.getLastRow(); var range = sheet.getRange(1, 1, lastRow - 2, 15); range.removeDuplicates(); organizarDados(); }

function organizarDados() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var range = sheet.getRange(2, 2, sheet.getLastRow() - 2, 15); var sort = range.sort({ column: 2, ascending: true }); sort.sort({ column: 4, ascending: true }); }

Javascript
View
generate functionWed, 11 Jan 2023

click on element with id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar" mouse hover element id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" click on <a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

def export_to_csv(): driver.find_element_by_id("ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar").click() WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao"))).click() driver.find_element_by_css_selector("#ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_mnExportacao > td > a").click()

Python
View
generate functionWed, 11 Jan 2023

check if element with id ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem exists in page if true, clicks it. If not foud, resume script execution

def check_for_data(): try: driver.find_element_by_id('ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem') except NoSuchElementException: return False else: driver.find_element_by_id('ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem').click() return True

Python
View
generate functionTue, 17 Jan 2023

improve the following function so it compares columns A:K of the row, and when it is duplicate, it removes the whole row function removerDuplicatas() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var lastRow = sheet.getLastRow(); var range = sheet.getRange(1, 1, lastRow - 2, 15); range.removeDuplicates(); }

function removerDuplicatas() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var lastRow = sheet.getLastRow(); var range = sheet.getRange(1, 1, lastRow - 2, 15); range.removeDuplicates(); }

Javascript
View
generate functionTue, 10 Jan 2023

1. get the date stored in ultimaData.txt as the value for variable ultimaData 2. if no date is retrieved, make the value of ultimaData 30 days before today (DD/MM/AAAA) 3. fill the field named ctl00$ContentPlaceHolder1$txtSelDataInicio with the value of ultimaData 4. click the button ctl00$ContentPlaceHolder1$btnConsultar 5. erase the contents of ultimaData.txt, saving today's date in it (DD/MM/AAAA)

def getData(): global driver global ultimaData ultimaData = open("ultimaData.txt", "r") ultimaData = ultimaData.read() if ultimaData == "": ultimaData = datetime.now() + timedelta(-30) ultimaData = ultimaData.strftime("%d/%m/%Y") driver.find_element_by_name("ctl00$ContentPlaceHolder1$txtSelDataInicio").send_keys(ultimaData) driver.find_element_by_name("ctl00$ContentPlaceHolder1$btnConsultar").click() ultimaData = datetime.now().strftime("%d/%m/%Y") ultimaData = open("ultimaData.txt", "w") ultimaData.write(ultimaData) ultimaData.close()

Python
View
generate functionWed, 11 Jan 2023

click all checkboxes with ids like ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl01_chkDataJornalItem, ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl02_chkDataJornalItem, and so on, all the way to ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl99_chkDataJornalItem, stopping when a checkbox with a given number is not found

def click_all_checkboxes_with_id(id_prefix, id_suffix, max_id_number): for i in range(0, max_id_number): id = id_prefix + str(i).zfill(2) + id_suffix try: checkbox = WebDriverWait(browser, delay).until(EC.element_to_be_clickable((By.ID, id))) checkbox.click() except TimeoutException: return

Python
View
generate functionThu, 26 Jan 2023

a descrição abaixo é referente a uma planilha google quanto eu editar a coluna Q da aba Página1, preciso preencher as seguintes células da mesma linha (todos os exemplos a seguir são referentes à linha 3): 1) L, com o valor correspondente ao resultado da fórmula =TODAY() 2) M, com o valor equivalente ao resultado da fórmula =REPLACE(G3; 16; 10; "") 3) N, com o valor equivalente ao resultado da fórmula =REPLACE(G3; 1; 21; "") 4) O, com a palavra "peticionar" (mesmo se a célula já estiver preenchida) 5) R, buscando o conteúdo da célula editada na coluna A da aba dados e escrevendo o conteúdo da mesma linha da coluna B dessa mesma aba (somente se a célula destino estiver vazia) 6) W, buscando o conteúdo da célula editada na coluna A da aba dados e escrevendo o conteúdo da mesma linha da coluna F dessa mesma aba (mesmo se a célula já estiver preenchida)

function onEdit(e) { //uncomment the line below to see which columns are being edited //Logger.log(e); //set the sheet where the data is var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Página1"); //set the cell where the date should be inserted var cell = e.range.offset(0, -16); //if the column is Q, the row number is greater than 2 and the cell is empty if (e.range.getColumn() == 17 && e.range.getRow() > 2 && cell.isBlank()) { //set the date in the cell cell.setValue(new Date()).setNumberFormat("dd/MM/yyyy"); } //set the cell for the date cell = e.range.offset(0, -14); //if the column is Q, the row number is greater than 2 and the cell is empty if (e.range.getColumn() ==

Javascript
View
generate functionWed, 11 Jan 2023

click the checkbox in the element <div id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_divItem" class="div-item"> <div> <a id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_lnkDataPub" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$dtlDataJornalPublicacao$ctl00$lnkDataPub','')">10/01/2023</a> </div> <label class="container-label"> <input id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem" type="checkbox" name="ctl00$ContentPlaceHolder1$dtlDataJornalPublicacao$ctl00$chkDataJornalItem"> <span class="checkmark"></span> </label> <span id="ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_lblJornal" style="color: gray">DJ SP (16) </span> </div>

from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException def click_ckbox(driver, checkbox_id): try: element_present = EC.presence_of_element_located((By.ID, checkbox_id)) WebDriverWait(driver, 2).until(element_present) checkbox = driver.find_element_by_id(checkbox_id) if checkbox.is_selected(): print("Checkbox already selected") else: checkbox.click() print("Checkbox selected") except TimeoutException: print("Timed out waiting for page to load") click_ckbox(driver, 'ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem')

Python
View
generate functionWed, 11 Jan 2023

clicar em <div id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar"> mouse over div id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlMenuExportacao" class="popup_menu" style="visibility: hidden; position: absolute; left: 286px; top: 6347px; z-index: 1000; display: none;"> clicar em <td style="white-space:nowrap;width:100%;"><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$ListaPublicacaoResultado$mnExportacao','histxls')" style="text-decoration:none;">Planilha</a></td> </tr>

from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Chrome() driver.get('http://www.cnj.jus.br/busca-atos-administrativos?no_documento=&tipo_autor=0&tipo_ato=0&tipo_data=0&data_inicial=&data_final=&assunto=&numero_processo=&interessado=&id_coordenacao=0&id_orgao_julgador=&id_unidade_julgadora=0&id_relator=&id_orgao=0&id_orgao_superior=0&ordenacao=0&pagina=1') dropdown_menu_element = driver.find_element_by_xpath('//div[@id="ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_pnlExportar"]') dropdown_menu = ActionChains(

Python
View

Questions about programming?Chat with your personal AI assistant