auto-setting price for minted NFT collection on OpenSea - python

Im trying to sell minted NFT collection on OpenSea with this script:
# Set price
for i in range(10000): # See if it's there
try:
chrome.find_element(By.XPATH, '//input[#name="price"]')
break
except:
time.sleep(0.5)
chrome.find_element(By.XPATH, '//input[#name="price"]').send_keys(price + Keys.RETURN)
# Click sign
for i in range(10000):
try:
chrome.find_element(By.XPATH, '//button[text()="Sign"]')
break
except:
time.sleep(0.5)
chrome.find_element(By.XPATH, '//button[text()="Sign"]').click()
# scroll
chrome.find_element(By.XPATH, '//div[#data-testid="signature-request-scroll-button"]').click()
# waiting unblock button
time.sleep(1)
# sign
chrome.find_element(By.XPATH, '//button[text()="Sign"]').click()
and the script stuck when Metamask ask for sign transaction because of "scroll down" button

Related

How can I handle pyautogui screenshot error?

I'm trying to code "Keep what you are doing, when ss.png has seen on screen, do this instead" but it only prints None again and again. What should I do?
try:
image = gui.locateOnScreen("ss.png")
print(image)
except:
gui.click(296, 47, clicks=3, interval=0.25)
gui.press("enter")
time.sleep(2)
gui.click(499, 484, clicks=3, interval=0.25)
time.sleep(5)
gui.click(505, 585)
gui.press("enter")
time.sleep(5)
gui.click(133, 223)
time.sleep(2)
gui.click(477, 101)
time.sleep(3)
time.sleep(5)
gui.click(667, 376)
time.sleep(40)
gui.click(1225, 106)
time.sleep(2)
gui.click(1175, 269)
time.sleep(5)
counter = counter + 1

monitor chrome tabs - python selenium

I'm writing a script where I need you to monitor the number of open tabs. The script reads a table and each information in the table opens a new tab in the browser. It turns out that in order not to have thousands of tabs open, I need the script to monitor the tabs to have only 3 open, when I close a tab I need to automatically open the next tab
def base_dados_processos(self):
try:
df = pd.read_excel('TABLE.xlsx')
self.num_proc = df['COLUM']
except Exception:
pg.alert(text='error', title='ERROR', button='OK')
self.chrome.quit()
def loop_pesquisa(self):
for PROCESSOS in zip(self.num_proc):
num_current_tabs = len(self.chrome.window_handles)
if num_current_tabs < 3:
pg.hotkey('ctrl', '1')
time.sleep(1)
self.chrome.get('https://stackoverflow.com/')
pg.write(str(test))
pg.press('enter')
time.sleep(3)
pg.press('tab', presses=26)
pg.press('enter')
time.sleep(1)
pg.press('enter')
To do this, just add a loop that monitors the guides, it can be as follows:
while len(self.chrome.window_handles) > 3:
time.sleep(0.5)
without your code:
def base_dados_processos(self):
try:
df = pd.read_excel('TABLE.xlsx')
self.num_proc = df['COLUM']
except Exception:
pg.alert(text='error', title='ERROR', button='OK')
self.chrome.quit()
def loop_pesquisa(self):
for PROCESSOS in zip(self.num_proc):
while len(self.chrome.window_handles) > 3:
time.sleep(0.5)
pg.hotkey('ctrl', '1')
time.sleep(1)
self.chrome.get('https://stackoverflow.com/')
pg.write(str(test))
pg.press('enter')
time.sleep(3)
pg.press('tab', presses=26)
pg.press('enter')
time.sleep(1)
pg.press('enter')

raspberry pi people count to google form

I am trying to count people who break a laser beam (hardware works) and then post to google form.
code:
###################################################
######### People Counter v1-1 ############
###################################################
################################
###Setting up Python Modules####
################################
import RPi.GPIO as GPIO
import os, time
################################
##### Setting up GPIO pins #####
################################
RECEIVER_PIN = 23
################################
######Setting up Counters ######
################################
peoplecount = 0
uploadcount = 0
door = 1 # <- Use this to designate multiple doors for tracking
location = 'Entry' # <- Use this to designate multiple locations for tracking in one form
rpitemp = 'vcgencmd measure_temp | cut -c6-7' # Temperatur vom RPi
def callback_func(channel):
if GPIO.input(channel):
print("Lichtschranke wurde unterbrochen")
## This waits for a specified minute of the hour, checks if anyone has been detected since the last upload, then uploads the data to a Google Form.
# if time.strftime("%M") in ("13", "28", "43", "58") and peoplecount > 0 and uploadcount == 0:
global peoplecount
global uploadcount
if peoplecount > 0 and uploadcount == 0:
try:
url = 'https://docs.google.com/forms/d/e/1FAIpQLSduNOOwMUtpQc5QNFbcwPXQhD0MRppum3kkYHThkFvo0JluQw/formResponse?entry.664100658=%s&entry.1901373746=%s&entry.1382055524=%s&entry.718436324=%s&submit=Senden' % (location, door, peoplecount, rpitemp)
response = br.open(url)
print "People count uploaded with value %s on door %s at %s and RPi Temp %s" % (peoplecount, door, location, rpitemp)
uploadcount = 0
peoplecount = 0
print "values reset"
except:
print "Cannot Access Page"
elif time.strftime("%M") in ("38", "39", "40", "41") and uploadcount == 1:
uploadcount = 0
elif GPIO.input(RECEIVER_PIN) == True:
peoplecount = peoplecount + 1
print "Motion Detected: Door %s at %s on %s. Count is %s" % (door, time.strftime("%H:%M:%S"), time.strftime("%A"), peoplecount)
time.sleep(3)
if __name__ == '__main__':
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RECEIVER_PIN, GPIO.IN)
GPIO.add_event_detect(RECEIVER_PIN, GPIO.RISING, callback=callback_func, bouncetime=200)
try:
while True:
time.sleep(0.5)
except:
# Event wieder entfernen mittels:
GPIO.remove_event_detect(RECEIVER_PIN)
error:
Lichtschranke wurde unterbrochen
Motion Detected: Door 1 at 19:47:22 on Friday. Count is 1
Cannot Access Page
It seems that the variables don't send any data. If I don't send the form with %s it works. Can anybody help me or is there a better method?
I think you are using the Browser module to open the URL. If so you haven't imported the browser module. So that's why it's throwing an exception and printing cannot Access page
from mechanize import Browser
br = Browser()
Install the module using PIP and add this at the start of the code. This should help

How can I seperate the find_element and switch_to codelines into different module?

I am working on the infrastructure for the GUI automation in my company. I am new to python and a total amateur in writing SW (my expertise is HW).
I started experimenting python and selenium and got to a point where I look forward and see a certain implementation problem.
The following is an example of a script that is actually a short test plan:
from selenium import webdriver
from datetime import datetime
import time
def main():
i = 0
while True:
i = i +1
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
browser = webdriver.Firefox(firefox_profile = profile)
browser.implicitly_wait(20) # Implicit wait
try:
execute_code(i, browser)
browser.quit()
if i == 500:
break
except:
browser.quit()
def Cold_Restart(browser):
browser.switch_to.default_content()
browser.switch_to.frame('box_menu')
browser.switch_to.frame('box_menu')
SysBtn = browser.find_element_by_id('System')
SysBtn.click()
browser.switch_to.default_content()
browser.switch_to.frame('main_menu')
Mainten_Btn = browser.find_element_by_id('Maintenance')
Mainten_Btn.click()
browser.switch_to.default_content()
browser.switch_to.frame('main_body')
Mntn_Rst_Tab = browser.find_element_by_id('tab_restart')
Mntn_Rst_Tab.click()
browser.switch_to.frame('maint_sys')
Cold_Rst_Btn = browser.find_element_by_id('cold_restart')
Cold_Rst_Btn.click()
#In order to confirm the Alert Message I first need to switch to the alert pop-up message and then accept it
alertDialog = browser.switch_to_alert()
alertDialog.accept()
time.sleep(205)
return
def Port_Admin_Down(browser):
browser.switch_to.default_content()
browser.switch_to.frame('box_menu')
browser.switch_to.frame('box_menu')
Port_19 = browser.find_element_by_id('Port-19')
Port_19.click()
browser.switch_to.default_content()
# Show the Port Configuration TAB
browser.switch_to.frame('main_body')
CFP2_Info = browser.find_element_by_id('tab_general')
CFP2_Info.click()
browser.switch_to.frame('config_port') # Move to the inner frame that holds the configuration fields and buttons
Admin_Down_Btn = browser.find_element_by_id('red_button')
Admin_Down_Btn.click()
#In order to confirm the Alert Message I first need to switch to the alert pop-up message and then accept it
alertDialog = browser.switch_to_alert()
alertDialog.accept()
time.sleep(5)
return
def Port_Admin_Up(browser):
browser.switch_to.default_content()
browser.switch_to.default_content()
browser.switch_to.frame('box_menu')
browser.switch_to.frame('box_menu')
Port_19 = browser.find_element_by_id('Port-19')
Port_19.click()
browser.switch_to.default_content()
# Show the Port Configuration TAB
browser.switch_to.frame('main_body')
CFP2_Info = browser.find_element_by_id('tab_general')
CFP2_Info.click()
browser.switch_to.frame('config_port') # Move to the inner frame that holds the configuration fields and buttons
Admin_Down_Btn = browser.find_element_by_id('green_button')
Admin_Down_Btn.click()
#In order to confirm the Alert Message I first need to switch to the alert pop-up message and then accept it
alertDialog = browser.switch_to_alert()
alertDialog.accept()
time.sleep(5)
return
def Gui_Login(browser, URL):
browser.get(URL)
# browser.implicitly_wait(20) # Implicit wait
browser.maximize_window()
# Find the User Name text box and fill the User name
user_name_box = browser.find_element_by_id('u_name_box')
user_name_box.click()
user_name_box.send_keys('admin')
# Find the Password text box and fill the Password
user_pass_box = browser.find_element_by_id('u_pass_box')
user_pass_box.click()
user_pass_box.send_keys('admin')
#webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
login_button = browser.find_element_by_id('login_but')
login_button.click()
return
def Gui_Logout(browser):
browser.switch_to.default_content() # Get back to the default starting point
# In order to click the Logout button I needed to pass through two frames
browser.switch_to.frame('box_menu')
browser.switch_to.frame('box_menu')
logout_btn = browser.find_element_by_id('Logout')
logout_btn.click()
return
def Sample_Uplink(browser):
browser.switch_to.default_content()
# Go to the Configuration Pane (main_menu)
browser.switch_to.frame('main_menu')
Configuration_Btn = browser.find_element_by_id('Configuration')
Configuration_Btn.click()
browser.switch_to.default_content()
# Go to the Uplink 1 CFP2 information and take the Rx Pwr
browser.switch_to.frame('box_menu')
browser.switch_to.frame('box_menu')
Port_19 = browser.find_element_by_id('Port-19')
Port_19.click()
browser.switch_to.default_content()
# Show the Optic Module information TAB
browser.switch_to.frame('main_body')
CFP2_Info = browser.find_element_by_id('tab_XFP')
CFP2_Info.click()
# Collect the Rx Pwr from the CFP2 Info screen
browser.switch_to.frame('config_port') # Move to the inner frame that holds all the tables
#browser.find_element_by_class_name('table_round_corner')
Rx_Pwr = browser.find_element_by_xpath('html/body/form/div[1]/div/table/tbody/tr[2]/td[2]') # Take the Rx Pwr according to its Xpath
# print (Rx_Pwr.text) # print the Rx Pwr result to screen
RcvPwr = Rx_Pwr.text
# Collect the OSNR measurement from the CFP2 Info screen
OSNR = browser.find_element_by_xpath('html/body/form/div[1]/div/table/tbody/tr[4]/td[2]')
OSNR_Lvl = OSNR.text
# time.sleep(5)
return (RcvPwr, OSNR_Lvl)
def Save_2_File(Rx_Pwr, OSNR_Lvl, i):
file = open("test_results.txt", "a")
file.write("%i. " %i)
file.write(datetime.now().strftime('%H:%M:%S %d-%m-%Y ')) # Print Time & Date to the text file
file.write(Rx_Pwr) # Print the Rx_Pwr to the text file
file.write('%10s' %(OSNR_Lvl)) # Format the placement of the OSNR value
file.write('\n') # Make sure that the next iteration will write the results in the next line
file.close() # Closing the file
return
def execute_code(i, browser):
#===========================================================================
# Cold Restart Recovery test
#===========================================================================
URL1 = 'http://10.0.1.131' # First device that will be Cold Restarted
Gui_Login(browser, URL1)
Cold_Restart(browser)
(RcvPwr, OSNR_Lvl) = Sample_Uplink(browser)
Save_2_File(RcvPwr, OSNR_Lvl, i)
URL2 = 'http://10.0.1.134'
Gui_Login(browser, URL2)
Cold_Restart(browser)
(RcvPwr, OSNR_Lvl) = Sample_Uplink(browser)
Save_2_File(RcvPwr, OSNR_Lvl, i)
#===========================================================================
# Local Uplink Down --> Up
#===========================================================================
browser.get(URL1)
Port_Admin_Down(browser)
Port_Admin_Up(browser)
time.sleep(5)
browser.get(URL2)
#Get Rx Pwr and OSNR and save in file
(RcvPwr, OSNR_Lvl) = Sample_Uplink(browser)
Save_2_File(RcvPwr, OSNR_Lvl, i)
#===========================================================================
# Remote Uplink Down --> Up
#===========================================================================
Port_Admin_Down(browser)
Port_Admin_Up(browser)
time.sleep(5)
browser.get(URL1)
#Get Rx Pwr and OSNR and save in file
(RcvPwr, OSNR_Lvl) = Sample_Uplink(browser)
Save_2_File(RcvPwr, OSNR_Lvl, i)
if __name__ == '__main__':
main()
My problem is that most of the script is actually find_elements and switch_frame commands. When I look forward, I want to see the Test Plan scripts cleaner while all the "dirty work" of finding (mapping) elements and switching frames is done in separate modules.
I separated these code lines into a different module and only then I realized that I have a certain problem. The browser variable is common to the module and the test script and shouldn't be opened twice (I think so).
How could this be done without losing the main objective which is the Test Plan?

How to close selenium drivers while multiprocessing in python on command?

I wrote a python script that uses multiprocessing to open up four different windows and search a common query among them; I'm trying to find a way to close the drivers on command instead of calling driver.close() at the end of the function which would automatically close the drivers as soon as they have successfully spawned.
I would like to browse the windows for a bit and close them when I am finished.
Here's what my code looks like:
def main(hosts, inp):
driver = webdriver.Chrome(executable_path='./chromedriver')
driver.get(hosts)
if 'ebay' in driver.current_url:
print 'opened ebay'
search_box = driver.find_element_by_id('gh-ac')
search_box.clear()
search_box.send_keys(inp)
search_box.send_keys(Keys.RETURN)
elif 'google' in driver.current_url:
print 'opened google'
search_box = driver.find_element_by_id('gbqfq')
search_box.clear()
search_box.send_keys(inp)
search_box.send_keys(Keys.RETURN)
elif 'etsy' in driver.current_url:
print 'opened etsy'
search_box = driver.find_element_by_id('search-query')
search_box.clear()
search_box.send_keys(inp)
search_box.send_keys(Keys.RETURN)
elif 'amazon' in driver.current_url:
print 'opened amazon'
search_box = driver.find_element_by_id('twotabsearchtextbox')
search_box.clear()
search_box.send_keys(inp)
search_box.send_keys(Keys.RETURN)
else:
print "--NONE--"
# driver.close()
if __name__ == '__main__':
hosts = ["http://ebay.com", "https://www.google.com/shopping?hl=en", "http://etsy.com", "http://amazon.com"]
num_hosts = len(hosts)
inp = raw_input("What do you want to search?: ")
p = Pool(num_hosts)
partial_main = partial(main, inp=inp)
p.map(partial_main, hosts)
p.close()
p.join()
I would like to do something like this:
done = raw_input("Type 'done' when finished:" )
if done = 'done':
driver.close()
but just injected that into main gives me an EOF error

Categories

Resources