Home > Back-end >  How should i click this type of log in with selenuim.py
How should i click this type of log in with selenuim.py

Time:12-27

im not sure how i should click this button be cause ive been trying to use content = driver.find_element(By.CLASS_NAME, 'content') but this just wont work. this part of the full code isnt suppose to log in but just press the loggin button.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

userUser = input('username: ')
userPass = input('Password: ')
NOF = input('insert amount of people to follow: ')

NOF = 10

chrome_driver_path = r'C:\Users\lukee\Downloads\Follower\chromedriver.exe'  # Optional argument, if not specified will search path.
browser = webdriver.Chrome(service=Service(chrome_driver_path))
browser.get('https://www.instagram.com/accounts/login/?next=https://www.instagram.com/login/?__coig_login=1')

time.sleep(2)

username = browser.find_element(By.NAME, 'username')
password = browser.find_element(By.NAME, 'password')

username.send_keys(userUser) 
password.send_keys(userPass) 



time.sleep(50)

this is the screen it goes to https://imgur.com/gCBa0oG

i dont know what to put here

CodePudding user response:

Something like this might work:

browser.find_element(By.XPATH, "//button[type='submit']").click()

CodePudding user response:

I think you can use find_element_by_xpath() (I don't know will be work or not, you must be test)

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By


userUser = input('username: ')
userPass = input('Password: ')
NOF = input('insert amount of people to follow: ')

NOF = 10

chrome_driver_path = r'C:\Users\lukee\Downloads\Follower\chromedriver.exe'  # Optional argument, if not specified will search path.
browser = webdriver.Chrome(service=Service(chrome_driver_path))
browser.get('https://www.instagram.com/accounts/login/?next=https://www.instagram.com/login/?__coig_login=1')

time.sleep(2)

username = browser.find_element(By.NAME, 'username')
password = browser.find_element(By.NAME, 'password')
login = browser.find_element(By.XPATH('/html/body/div[2]/div/div/div/div[1]/div/div/div/div[1]/section/main/article/div[2]/div[1]/div[2]/form/div/div[3]/button')).click()


username.send_keys(userUser) 
password.send_keys(userPass) 
login.click()

time.sleep(50)

CodePudding user response:

you could use the .click() method, as such:

content = driver.find_element(By.CLASS_NAME, 'content')
content.click()

or, somewhat different stylistically, Keys.ENTER:

username.send_keys(userUser) 
password.send_keys(userPass)
password.send_keys(Keys.ENTER)

the second block of code will submit the web form with a post request on most login forms, and the first block will attempt it as well which should succeed provided all required fields (name and password) are filled out.

  • Related