Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

» Selecting the input for auto populating element
Sat Jul 29, 2017 7:53 pm by kdabbara

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Google Recpatcha -: Convert from python to java

View previous topic View next topic Go down

Google Recpatcha -: Convert from python to java

Post by akshatj on Thu Jan 19, 2017 8:03 pm

Please convert this python code to java code for Google Recaptcha

import re, csv
from time import sleep, time
from random import uniform, randint
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException    

def write_stat(loops, time):
with open('stat.csv', 'a', newline='') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow([loops, time])    

def check_exists_by_xpath(xpath):
    try:
        driver.find_element_by_xpath(xpath)
    except NoSuchElementException:
        return False
    return True

def wait_between(a,b):
rand=uniform(a, b) 
sleep(rand)
 
def dimention(driver): 
d = int(driver.find_element_by_xpath('//div[@id="rc-imageselect-target"]/table').get_attribute("class")[-1]);
return d if d else 3  # dimention is 3 by default

# ***** main procedure to identify and submit picture solution
def solve_images(driver):
WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID ,"rc-imageselect-target"))
        )
dim = dimention(driver)
# ****************** check if there is a clicked tile ******************
if check_exists_by_xpath('//div[@id="rc-imageselect-target"]/table/tbody/tr/td[@class="rc-imageselect-tileselected"]'):
rand2 = 0
else:  
rand2 = 1 

# wait before click on tiles
wait_between(0.5, 1.0)  
# ****************** click on a tile ****************** 
tile1 = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH ,   '//div[@id="rc-imageselect-target"]/table/tbody/tr[{0}]/td[{1}]'.format(randint(1, dim), randint(1, dim )))) 
)   
tile1.click() 
if (rand2):
try:
driver.find_element_by_xpath('//div[@id="rc-imageselect-target"]/table/tbody/tr[{0}]/td[{1}]'.format(randint(1, dim), randint(1, dim))).click()
except NoSuchElementException:          
   print('\n\r No Such Element Exception for finding 2nd tile')
   
 
#****************** click on submit buttion ****************** 
driver.find_element_by_id("recaptcha-verify-button").click()

start = time()  
url='...'
driver = webdriver.Firefox()
driver.get(url)

mainWin = driver.current_window_handle  

# move the driver to the first iFrame 
driver.switch_to_frame(driver.find_elements_by_tag_name("iframe")[0])

# *************  locate CheckBox  **************
CheckBox = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID ,"recaptcha-anchor"))
        ) 

# *************  click CheckBox  ***************
wait_between(0.5, 0.7)  
# making click on captcha CheckBox 
CheckBox.click() 
 
#***************** back to main window **************************************
driver.switch_to.window(mainWin)  

wait_between(2.0, 2.5) 

# ************ switch to the second iframe by tag name ******************
driver.switch_to_frame(driver.find_elements_by_tag_name("iframe")[1])  
i=1
while i<130:
print('\n\r{0}-th loop'.format(i))
# ******** check if checkbox is checked at the 1st frame ***********
driver.switch_to.window(mainWin)   
WebDriverWait(driver, 10).until(
        EC.frame_to_be_available_and_switch_to_it((By.TAG_NAME , 'iframe'))
        )  
wait_between(1.0, 2.0)
if check_exists_by_xpath('//span[@aria-checked="true"]'): 
                import winsound
winsound.Beep(400,1500)
write_stat(i, round(time()-start) - 1 ) # saving results into stat file
break 

driver.switch_to.window(mainWin)   
# ********** To the second frame to solve pictures *************
wait_between(0.3, 1.5) 
driver.switch_to_frame(driver.find_elements_by_tag_name("iframe")[1]) 
solve_images(driver)
i=i+1

akshatj

Posts : 1
Join date : 2017-01-19

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum