pause execution
import time
time.sleep(3)
All generations.
import time
time.sleep(3)
# 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)
def enterData(driver, field_name, value):
elem = driver.find_element_by_name(field_name)
elem.clear()
elem.send_keys(value)
driver.find_element_by_id("ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem").click()
def wait_for_element_clickable_by_xpath(xpath):
try:
element = WebDriverWait(driver, 600).until(
EC.element_to_be_clickable((By.XPATH, xpath))
)
except:
print("Element 'ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem' is not clickable")
return element
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)
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)
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)
def export_to_excel(driver):
driver.find_element_by_id('ctl00_ContentPlaceHolder1_ListaPublicacaoResultado_imbExportarTodas').click()
time.sleep(2)
driver.find_element_by_link_text('Planilha').click()
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.
def pause():
input("Press <enter> to continue...")
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
def check_data_jornal(page):
page.find_element_by_id('ctl00_ContentPlaceHolder1_dtlDataJornalPublicacao_ctl00_chkDataJornalItem')
return True
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")
# -*- 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
The function removerDuplicatas()
returns the sum of a and b.
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.
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
});
}
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()
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
function removerDuplicatas() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var lastRow = sheet.getLastRow();
var range = sheet.getRange(1, 1, lastRow - 2, 15);
range.removeDuplicates();
}
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()
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
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() ==
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')
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(
Generate
More than just a code generator. A tool that helps you with a wide range of tasks. All in one place.
Function from Description
Text Description to SQL Command
Translate Languages
Generate HTML from Description
Code to Explanation
Fix invalid Code
Get Test for Code
Class from Description
Regex from Description
Regex to Explanation
Git Command from Description
Linux Command
Function from Docstring
Add typing to code
Get Language from Code
Time complexity
CSS from Description
Meta Tags from Description