Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I forgot my password and I wrote this code with Selenium to try to recover my pass, but I don't know how to continue.
The button new password doesn't work.
Can someone help me? I try different ways to continue but I don't know. Is any way to enter?
I am trying to remember my password using the function. Something like force brute. So, I dont know how to make a loop generating a new password, with the function, enter it in the box "Contraseña: " until it is correct
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time
import os
import datetime
from datetime import datetime
from playsound import playsound
import smtplib, ssl
from random import sample
def password_generator(longitud):
abc_minusculas = "abcdefghijklmnopqrstuvwxyz"
abc_mayusculas = abc_minusculas.upper()
numeros = "0123456789"
secuencia = abc_minusculas + abc_mayusculas + numeros
password_union = sample(secuencia, longitud)
password_result = "".join(password_union)
return password_result
PATH = "C:\Program Files (x86)\Chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("http://siga.frba.utn.edu.ar/")
print(driver.title)
link = driver.find_element_by_id("page-try")
link.click()
time.sleep(1)
link = driver.find_element_by_xpath('//*[#id="menu-page-try"]/p[4]/a')
link.click()
time.sleep(1)
search = driver.find_element_by_name("form_email")
search.send_keys("35335")
search.send_keys(Keys.RETURN)
time.sleep(0.5)
1 The locator you used is not unique (there are two of them). So I replaced it with xpath locator //input[#name='form_email'].
2 You are using time.sleep everywhere. It may be slower then using Selenium's explicit/implicit wait and also it's very unstable
So, I added wait = WebDriverWait(driver, 30) to your code and applied explicit waits.
3 Also, I noticed that page-try id is not unique, so I replaced it with css selector. If you are using find_element..., not find_elements... then your locators have to be unique.
Solution
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
import time
import os
import datetime
from datetime import datetime
import smtplib, ssl
from random import sample
PATH = '/snap/bin/chromium.chromedriver'
driver = webdriver.Chrome(executable_path=PATH)
driver.get("http://siga.frba.utn.edu.ar/")
print(driver.title)
wait = WebDriverWait(driver, 30)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#page-try"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//a[contains(text(), 'Usuarios registrados')]"))).click()
search = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#name='form_email']")))
search.send_keys("35335")
search.send_keys(Keys.RETURN)
To click Solicitar nueva contraseña button use this xpath: //a[contains(text(), 'Solicitar nueva contraseña')]
Try using the locators I provided as examples for other elements on your site. Use this as a reference https://www.w3schools.com/xml/xpath_intro.asp
Related
Ive been attempting to use selenium to go through elements on soundclouds website and am having trouble interacting with the input tags. When I try to write in the input tag of the class "headerSearch__input" with the send keys command, I get back the error "Message: element not interactable". May someone please explain to me what im doing wrong?
from tkinter import *
import random
import urllib.request
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import requests
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome(executable_path='/Users/quanahbennett/PycharmProjects/SeleniumTest/chromedriver')
url= "https://soundcloud.com/"
driver.get(url)
#time.sleep(30)
wait = WebDriverWait(driver, 30)
#link = driver.find_elements_by_link_text("Sign in")
#link[0].click()
#driver.execute_script("arguments[0].click();", link[0])
#SUCCESFUL LOGIN BUTTON PUSH
#please = driver.find_element_by_css_selector('button.frontHero__loginButton')
#please.click()
attempt = driver.find_element_by_css_selector('input.headerSearch__input')
time.sleep(10)
attempt.send_keys('Hello')
breakpoint()
#driver.quit()
The locator - input.headerSearch__input is highlighting two different elements in the DOM. Its important to find unique locators. Link to refer
And also close the cookie pop-up. And then try to interact with elements.
Try like below and confirm.
driver.get("https://soundcloud.com/")
wait = WebDriverWait(driver,30)
# Click on Accept cookies button
wait.until(EC.element_to_be_clickable((By.ID,"onetrust-accept-btn-handler"))).click()
search_field = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[#id='content']//input")))
search_field.send_keys("Sample text")
I have tried looking for solutions all around SO and integrated answers to no avail. I am trying to fill up dynamic #id forms and applying my code logic to both my test site and udemy does not seem to work.
driver.get('https://www.udemy.com/')
#search= driver.find_element_by_xpath('//*[contains(#id,"-search-form-autocomplete--3")')
s = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[contains(#id,"-search-form-autocomplete--3")')))
s.send_keys("robotics")
xpath is not closed properly the closing ] is missing hence may be the exception. Another thing is please add the necessary imports
when I fixed the xpath your code did worked for me -
Code after fix-
driver = webdriver.Chrome()
driver.get('https://www.udemy.com/')
#search= driver.find_element_by_xpath('//*[contains(#id,"-search-form-autocomplete--3")')
s = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//*[contains(#id,"-search-form-autocomplete--3")]')))
s.send_keys("robotics")
Imports needed -
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Output -
Did you put from selenium.webdriver.common.keys import Keys in your code?
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have tried all ways possible to locate the bellow import file window elements from google sheets and yet haven't locate it. Here is the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
import time
import pynput
from pynput.keyboard import Key, Controller
keyboard = Controller()
import os
import logging
import glob
#save chrome user data to chromedriver
options = webdriver.ChromeOptions()
options.add_argument("") #Path to your chrome profile
driver = webdriver.Chrome(executable_path="C:\\Program Files (x86)\\chromedriver.exe", chrome_options=options)
#open the google sheet in chrome
driver.get("https://docs.google.com/spreadsheets/d/")
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))
#click on file menue
wait3 = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "docs-file-menu")))
driver.find_element_by_id("docs-file-menu").click()
#click on import
wait3 = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.ID, ":4q")))
driver.find_element_by_id(":4q").click()
Google Sheet import Window
The Element which you are looking for is in the iframe.
First, you have to switch to that iframe and then start searching for your element.
So basically i made a little selenium script and i want to save the pass word and email in a different file for easy editing.
For some reason passing the variables is not working and i cant make heads and tails. i get this error:
unused import statement(when i hover over the import line from Details import *)
I still struggle a bit with Python and would love if you dont bash me for a probably obvious mistake :P
Edit: the programm itsself works fine its just when i try to pass variables that it messes up.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from Details import *
driver = webdriver.Firefox()
url = "https://discordapp.com/channels/530588470905929729/538868623981412362"
driver.get(url)
email = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[#type='email']")))
email.send_keys(email)
password = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//input[#type='password']")))
password.send_keys(password + Keys.ENTER)
sleep(5)
textbox = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//textarea[#placeholder='Message #bot-commands']")))
textbox.send_keys("!work" + Keys.ENTER)
sleep(30)
driver.quit()
this is Details.py :
password = "Password"
email = "Email#email.com"
You use:
from Details import *
And Details contains a variable password. But your other code also has a different variable password.
Try:
import Details
imported_password = Details.password
i'm trying to login this site with selenium -python
but i can't .i read another question but i didn't get it.
how can i do it?
this my error:
enter image description here
this is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.get("https://en.gamefa.com/")
driver.find_element_by_name("loginform").submit()
driver.find_element_by_class_name("ModalBoxBody")#.submit()
time.sleep(10)
elem1 = driver.find_element_by_name("log")
elem1.send_keys("mehrdad78")
elem2 = driver.find_element_by_name("pwd")
elem2.send_keys("mehrdad78").submit()
First, Your screenshot is not giving us enough data about the error. Post the error stack trace which directs to your code.
Second, all the items have id. It would be better to use id to find elements.
Third, Click does work. Submit doesn't work on buttons. using submit on an element outside a form should throw an exception.
Fourth, Use explicit wait instead of sleep.
Try this
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
driver.get("https://en.gamefa.com/")
driver.find_element_by_id("login-form").click()
elem1 = WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.ID, "user_login3")).send_keys("mehrdad78")
elem2 = driver.find_element_by_id("user_pass3").send_keys("mehrdad78")
elem3 = driver.find_element_by_id("wp-submit3").submit()