JorgeLuzz 0 Posted March 21, 2020 Report Share Posted March 21, 2020 (edited) Boa noite, Tenho uma duvida Como importo dados de txt ou de csv para selenium por exemplo Tabela Nome,Email,Data_Nascimento Jorge,@test.com,07/05/1990 Jorge,@test.com,07/05/1990 Jorge,@test.com,07/05/1990 Jorge,@test.com,07/05/1990 Queria fazer import e loop para continuar ate nao existir mais conteudo na tabela. Nao sei se fui explicito. Nome.send_keys('NOME') time.sleep(1) EMAIL.send_keys('EMAIL') time.sleep(1) DATANAS.send_keys('DATANASCIMENTO') time.sleep(1) Edited March 21, 2020 by JorgeLuzz Cumprimentos Jorge Luz Link to post Share on other sites
M6 150 Posted March 21, 2020 Report Share Posted March 21, 2020 Vê aqui: https://chercher.tech/python/csv-selenium-python 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
JorgeLuzz 0 Posted March 21, 2020 Author Report Share Posted March 21, 2020 2 horas atrás, M6 disse: Vê aqui: https://chercher.tech/python/csv-selenium-python Obrigado,ja tinha tentado mas nao estou conseguir implementar no codigo vou continuar a testar. Cumprimentos Jorge Luz Link to post Share on other sites
JorgeLuzz 0 Posted March 21, 2020 Author Report Share Posted March 21, 2020 data = pd.read_excel (r'\Dados.xlsx') i = 0 while i == 0: a = 0 df = DataFrame(data) NomeD = df.nome UNomeD = df.ultimonome EmailD = df.emails TelD = df.telemovel Estou a usar o pandas NomeD = df.nome NameError: name 'df' is not defined Dá me esse erro Cumprimentos Jorge Luz Link to post Share on other sites
M6 150 Posted March 21, 2020 Report Share Posted March 21, 2020 A mensagem é bem clara, df não está definido. Estás a tentar usar o objeto df sem o ter definido. Vê lá se o teu "data" não devia ser o teu "df". 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
JorgeLuzz 0 Posted March 21, 2020 Author Report Share Posted March 21, 2020 Agora, M6 disse: A mensagem é bem clara, df não está definido. Estás a tentar usar o objeto df sem o ter definido. Vê lá se o teu "data" não devia ser o teu "df". Ja dei fix nisso agora aparece outro erro i = 0 while i == 0: a = 0 NomeD = data.nome ApelidoD = data.apelido EmailD = data.emails TelD = data.telemovel # Sends Nome Nome = driver.find_element_by_id('first_name') Nome.send_keys(NomeD[a]) # Sends Ultimo nome Ultimo = driver.find_element_by_id('last_name') Ultimo.send_keys(ApelidoD[a]) # Sends Email Email = driver.find_element_by_id('email') Email.send_keys(EmailD[a]) # Sends Telemovel Tel = driver.find_element_by_id('phone') Tel.send_keys(TelD[a]) # Click login driver.find_element_by_xpath('//*[@id="step_1"]/div[10]/button').click() TypeError: object of type 'numpy.float64' has no len() Cumprimentos Jorge Luz Link to post Share on other sites
JorgeLuzz 0 Posted March 22, 2020 Author Report Share Posted March 22, 2020 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import os import time import sys import pandas as pd import numpy as np import random import xlrd driver = webdriver.Chrome('C:\chromedriver') #Open the article link using get method driver.get('https://www.icmarkets.com/sc/pt/open-trading-account/live') data = pd.read_excel (r'http:\\localhost\Dados.xlsx') i = 0 while i == 0: a = 0 NomeD = data.nome ApelidoD = data.apelido EmailD = data.emails TelD = data.telemovel DiaD = data.day MesD = data.month AnoD = data.year MoradaD = data.morada CidadeD = data.cidade DistritoD = data.distrito CPostalD = data.codigopostal CPostalD2 = data.codigopostal2 # Insere Primeiro Nome Nome = driver.find_element_by_id('first_name') Nome.send_keys(str(NomeD[a])) # Insere Ultimo Nome Ultimo = driver.find_element_by_id('last_name') Ultimo.send_keys(str(ApelidoD[a])) # Insere Email Email = driver.find_element_by_id('email') Email.send_keys(str(EmailD[a])) # Insere Telemovel Tel = driver.find_element_by_id('phone') Tel.send_keys(int(TelD[a])) # Botao do Primeiro Passo driver.find_element_by_xpath('//*[@id="step_1"]/div[10]/button').click() time.sleep(10) # Insere Dia DDia = driver.find_element_by_id('birth_day') DDia.send_keys(int(DiaD[a])) # Insere Mes driver.find_element_by_xpath('//*[@id="birth_month"]').click() time.sleep(2) driver.find_element_by_xpath('//*[@id="mCSB_2_container"]/li['+ str(MesD[a]) +']').click() time.sleep(2) # Insere Ano DAno = driver.find_element_by_id('birth_year') DAno.send_keys(str(AnoD[a])) # Insere Morada Morada = driver.find_element_by_id('address') Morada.send_keys(str(MoradaD[a])) # Insere Cidade Cidade = driver.find_element_by_id('city') Cidade.send_keys(str(CidadeD[a])) # Insere Cidade Distrito = driver.find_element_by_id('state') Distrito.send_keys(str(DistritoD[a])) # Insere Codigo Postal CPostal = driver.find_element_by_id('zip_code') CPostal.send_keys(int(CPostalD[a]),'-',int(CPostalD2[a])) # Afiliado Fixo time.sleep(1) driver.find_element_by_xpath('//*[@id="step_2"]/div[5]/label').click() Afiliado = driver.find_element_by_id('reffer_id') Afiliado.send_keys('41618') time.sleep(1) # Finaliza Passo 2 driver.find_element_by_xpath('//*[@id="step_2"]/div[7]/button').click() time.sleep(10) ##STEP 3 driver.find_element_by_xpath('//*[@id="currency"]').click() time.sleep(1) driver.find_element_by_xpath('//*[@id="currenciesList"]/li[3]').click() time.sleep(1) driver.find_element_by_xpath('//*[@id="step_3"]/div[5]/button').click() time.sleep(5) ## STEP 4 ## VARIAVERIS STEP 4 Secreta = driver.find_element_by_id('security_answer') driver.find_element_by_xpath('//*[@id="step_4"]/div[1]/div[2]/div[2]').click() time.sleep(1) driver.find_element_by_xpath('//*[@id="security_question"]').click() time.sleep(1) driver.find_element_by_xpath('//*[@id="mCSB_6_container"]/li[1]').click() time.sleep(1) Secreta.send_keys('REGISTAR') time.sleep(1) driver.find_element_by_xpath('//*[@id="step_4"]/div[5]/div[2]/label').click() time.sleep(1) driver.find_element_by_xpath('//*[@id="step_4"]/div[6]/button').click() time.sleep(5) driver.find_element_by_xpath('/html/body/div[7]/div/div/div[3]/div/span').click() time.sleep(5) driver.get('https://www.icmarkets.com/sc/pt/open-trading-account/live') a = a + 1 Ja consegui passar varias barreiras, mas agora estou com problema queria que o script corre-se todas as linhas do ficheiro excel mas so corre a primeira, e repete sempre a primeira. Outro do problema está no Insere Mes como é uma listbox e ao abrir so aparece ate mes 7 se colocar mes 9 ele nao assume porque tem de dar scrool na listbox. Açguém me dá uma maozinha? Cumprimentos Jorge Luz Link to post Share on other sites
M6 150 Posted March 22, 2020 Report Share Posted March 22, 2020 Pelo que percebi do teu código, não está a iterar sobre os resultados do data. Se assim for, tens de fazer um loop por todos os resultados desse objeto. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
JorgeLuzz 0 Posted March 22, 2020 Author Report Share Posted March 22, 2020 3 horas atrás, M6 disse: Pelo que percebi do teu código, não está a iterar sobre os resultados do data. Se assim for, tens de fazer um loop por todos os resultados desse objeto. Já está Obrigado ja esta funcionar Só mais uma coisa sabes como fazer FileUpload pelo Windows Browser Clicar Botao com selenium e webdriver E abrir file e fazer upload browser do windows files? Cumprimentos Jorge Luz Link to post Share on other sites
M6 150 Posted March 23, 2020 Report Share Posted March 23, 2020 Nem percebi o que disseste... 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now