Home > Blockchain >  find_element_by_name selenium python question
find_element_by_name selenium python question

Time:12-15

I'm a beginner trying to use selenium to automate browser interactions through an undetectable chrome browser. The code i've done so far is below (you have no idea the time i've sunk into 5 lines).

I've tried so many iterations of the same code that I've lost sanity. This SHOULD work? This is almost copied exactly from a youtube video now, there were some other ideas that youtubers did use but I didn't understand the coding so I haven't touched them. Anything #'d can be ignored or assumed that i've played with it and failed.

import autogui, sys, time, webbrowser, selenium
import undetected_chromedriver.v2 as uc
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common import action_chains

#Open Browser and visit website.
driver = uc.Chrome()
driver.get('https://www.iqrpg.com/game.html')
time.sleep(5)

#Complete username and password fields
userN = 'Gary'
passW = 'Barry'
find_element_by_name('login_username').send_keys(userN)
#find_element_by_name('login_password').send_keys(passW)

#driver.find_element_by_css_selector("input[type=\"submit"

#userField =
#passField = driver.find_element(By.ID, "passwd-id")
#search_box = driver.find_element_by_name('Battling')
#search_box.send_keys('ChromeDriver')
#search_box.submit()
#time.sleep(5)

1.Expecting the browser to open, forcibly logging you out due to selenium chrome 2. select name='login_username', send key the string saved under userN 3. same for password 4. click login (not yet coded, but plans)

CodePudding user response:

In the latest Selenium with Python, you cannot use - driver.find_element_by_name.

Instead, you have to use: driver.find_element

from selenium.webdriver.common.by import By

driver.find_element(By.NAME, "login_username").send_keys("userN")
driver.find_element(By.NAME, "login_password").send_keys("passW")
  • Related