0

quick preface: I'm new to python and scraping so it's possible that I'm making an extremely obvious mistake.

I am trying to use Selenium to automate a few processes, the first of which is to open https://shop.anyseals.com/index.phtml and enter in a username and password.

This is how I am approaching it - A method that has worked for me without issue in the past with other websites.

from selenium import webdriver
import time

chromedriver = "A:\Downloads\chromedriver_win32 (1)/chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://shop.anyseals.com/index.phtml")

#Let's wait for X seconds so that the elements can load. 
time.sleep(3)

user = "username@user.com"
use = driver.find_element_by_xpath('//*[@id="userkey"]')

use.send_keys(user)

I'm using the xpath from the html associated with the username input. (html shown below)

<input name="userkey" id="userkey" style="width:100%" type="text"
 onkeydown="if(event.keyCode=='13')perform_login('smp');">

I keep getting the error shown below that states that there is no such element. What am I missing here?

selenium.common.exceptions.NoSuchElementException: 
Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="userkey"]"}
  • 2
    I took a quick look at the DOM, and I see the `input` element is inside an `iframe`. I bet that's the issue. Try switching to the `iframe` before locating the element, as suggested by [this StackOverflow question](https://stackoverflow.com/questions/18924146/selenium-and-iframe-in-html). – srk Apr 02 '21 at 03:15
  • Cool, a variation of that did work. This video helped a lot too. You were right, I had to switch to the iframe. Thanks!!! https://www.youtube.com/watch?v=NhRx99uFUNk – SuperIan89 Apr 02 '21 at 11:40

0 Answers0