Zdravim.
Existuje alternativa k selenium alebo nieco podobne co by riesilo problem otvarania stranky a vyplnenia formularu?
Ide o to ze mam externe zariadenie s ktoreho sa nacita ID. Selenium nasledne otvara stranku vyplna vstupne data a prihlasuje do systemu. Cele to mam funkcne ale je to neskutocne "divne" na bezne pouzitie. Idealne nieco co vie detekovat uz otvoreny browser a vykonat akciu v nom. Skusal som priamo webbrowser ale tam sa mi nepodarilo vyriesit problem s vlozenim udajov na web. (Ten viac menej riesil moj probem s pouzitim aktivneho prehliadaca)
import serial
import re
import subprocess
import win32com.client
import time
from selenium import webdriver
#Open serial connection
ser = serial.Serial()
ser.port = "COM7"
ser.baudrate = 9600
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
ser.timeout = 1 #non-block read
#ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
ser.open() # try to open port, if possible print message and proceed with 'while True:'
print ("port is opened!")
# Only trash
while (True):
if ser.is_open:
if (ser.inWaiting()>0):
time.sleep(0.5) #if incoming bytes are waiting to be read from the serial input buffer
data_str = ser.read(ser.inWaiting()).decode('ascii') #read the bytes and convert from binary array to ASCII
print(data_str, end='\n') #print the incoming string without putting a new-line ('\n') automatically after every print()
time.sleep(0.01)
#Open Browser
#browser exposes an executable file
#Through Selenium test we will invoke the executable file which will then #invoke actual browser
driver = webdriver.Chrome(executable_path="C:\driver\chromedriver.exe")
# to maximize the browser window
driver.maximize_window()
#get method to launch the URL
driver.get("http://XXXX/ads/idlogin.php?")
#to refresh the browser
driver.refresh()
# identifying the edit box with the help of id and enter text
driver.find_element_by_name("loginname").send_keys(data_str)
# identifying the button then using click() method
driver.find_element_by_xpath("//button[contains(@class,'submitbutton')]") .click()