Issue
I've made a bot that automatically logs me to my Instagram account. Everything works fine, except the fact that I can't automatically press the "Log In" button. This is the error I get:
Traceback (most recent call last):
File "C:/Users/Carole/PycharmProjects/InstagramBot1/main.py", line 40, in <module>
LoginPassword = ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.NAME, "password"))).send_keys(InstagramPassword).send_keys(Keys.ENTER)
AttributeError: 'NoneType' object has no attribute 'send_keys'
Process finished with exit code 1
And here's my code:
# Importing
from selenium.webdriver.chrome.service import Service
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.webdriver.support import ui
# Setting everything up
service = Service("\Program Files (x86)\chromedriver.exe")
# Maximizing Window
# Program Starts
RandomnessTime = input("Select Randomness time:")
InstagramUsername = input("Enter Username:")
InstagramPassword = input("Enter Password:")
#WaitRandomnessTime = "wait"+str(RandomnessTime)
driver = webdriver.Chrome(service=service)
driver.get('https://www.instagram.com/')
wait = ui.WebDriverWait(driver, 10)
driver.maximize_window()
wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, ".aOOlW.bIiDR"))).click()
RandomnessTime = WebDriverWait(driver, (1 - int(RandomnessTime)))
# Logging in
# def Login(self, )
LoginUsername = ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.NAME, "username"))).send_keys(InstagramUsername)
LoginPassword = ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.NAME, "password"))).send_keys(InstagramPassword).send_keys(Keys.ENTER)
# Clicking "Not Now".
ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.CSS_SELECTOR, ".aOOlW.HoLwm"))).click()
Can someone spot the problem with what I've written?
Solution
I would rather have this xpath
//div[text()='Log In']//parent::button
to click on Login button.
In you code something like this :
ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.XPATH, "//div[text()='Log In']//parent::button"))).click()
The issue that you've with your code is :
ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.NAME, "password"))).send_keys(InstagramPassword).send_keys(Keys.ENTER)
does not return anything, not sure why you have a returned variable for that.
If you wanna stick with your way, I would suggest to pass enter in same send_keys
like this.
ui.WebDriverWait(driver, 10).until(ec.element_to_be_clickable((By.NAME, "password"))).send_keys(InstagramPassword, Keys.ENTER)
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.