Selenium cannot find element by id on supreme website python
I'm making a bot that buys items from the supreme website using the selenium library for python 3.5. The bot can successfully add an item to the cart, but in the checkout process, selenium throws an error whenever it attempts to send keys to an input element found by the
find_element_by_id() method. Here's a simplified version of the code that throws the error.
from selenium import webdriver d = webdriver.Chrome() # First it adds an item to the cart d.get('http://www.supremenewyork.com/shop/tops-sweaters/vxdau6b3t/km1pzdca3') d.find_element_by_name('commit').click() # Then it goes to the checkout d.get('https://www.supremenewyork.com/checkout') name_box = d.find_element_by_id('order_billing_name') # This is the line that throws the error name_box.send_keys('name goes here')
Here's the full error message.
File "error.py", line 7, in <module> name_box.send_keys('name goes here') File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys 'value': keys_to_typing(value)}) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute return self._parent.execute(command, params) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute self.error_handler.check_response(response) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'. (Session info: chrome=66.0.3359.181) (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.3 x86_64)
When I replace the line
name_box = d.find_element_by_id('order_billing_name') with the line
d.find_element_by_xpath("//input[@id='order_billing_name']") the code works as intended. However, this isn't a viable solution as when the element is found this way, the
send_keys() method is very slow. Thanks for the help!
Let's try to do it correctly (of course there are a lot of things to improve, but I tried to keep it short. Please check the comments inline
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Chrome() # First it adds an item to the cart driver.get('http://www.supremenewyork.com/shop/tops-sweaters/vxdau6b3t/km1pzdca3') # wait until cart link is available add_to_cart = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "[name=commit]")) ) # add to cart add_to_cart.click() # wait until checkout link is available go_to_cart = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "div#cart:not(.hidden) a.checkout")) ) # Then it goes to the checkout go_to_cart.click() # wait until name input is available name_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CSS_SELECTOR, "div.order_billing_name")) ) # we can't select pseudo elements with css selector, but we can click on an element # above it, which is defined in "name_input", and emulate keypresses, # which are intended for the selected ("click()") element only actions = ActionChains(driver) actions.move_to_element(name_input).click().send_keys("hey 123").perform() driver.quit()
[Selenium] webdriver can't find element on webpage : learnpython, What would be a project that says to me "If you can do this you're ready for a job coding python"? edit: to be clear, I don't mean a job that makes me look like a But in case of unattended web access using webdriver, the driver can not just switch the windows automatically. We need to change the window handle in the driver to enter the login credentials in the popup window. Selenium have the function to switch the window to access multiple windows using the same driver.
According to chromedriver change note, please upgrade your chromedriver to 2.37 or 2.38 which is more compatible with chrome 66.
Building a Sniping Bot with Python (in the name of automated testing , Ever since, he has been complaining how hard it is for anyone to get his or her hands on Selenium is an open-source web-based automation tool often used for AsyncHTMLSession import time import config ''' python supreme.py only) element with id of “shop-scroller”, then finds all li elements within. FindElement command syntax: Find Element command takes in the By object as the parameter and returns an object of type WebElement. By object in turn can be used with various locator strategies such as ID, Name, Class Name, XPATH etc. Below is the syntax of FindElement command in Selenium web driver.
How to store value in variable in selenium webdriver, You will learn how to get any attribute's value of element using Selenium 27 Jul 2017 In the world of scripted automation tests, Selenium has long reigned supreme. Jun 07, 2015 · Each Array has a size and it can't take value more than the size of to locate an element based on the value of "ID" attribute on a web page. There are multiple ways to uniquely identify a web element/elements within the web page such as ID, Name, Class Name, Link Text, Partial Link Text, Tag Name and XPATH. Find Elements in Selenium WebDriver: Locator Strategy/ Types of locators. Locator Strategy can be one of the following types to find an element or FindElements –
How to Locate Elements using Selenium Python with Examples, In this tutorial, we'll explain how to locate elements on a web page and perform Click here to Go Back to main Selenium Python tutorial. 1. So, we should prefer using Id attribute for locating the elements over other available options. If the search doesn't succeed, the method will throw the NoSuchElementException. Using text method of selenium web driver, find the web element with text – Write and Earn. Validate if the selected element is displayed on the web page. If it is displayed, print the text as Element found using text. If the element is not displayed, print the text as Element not found.
selenium.common.exceptions.ElementNotInteractableException , You can check first if the element is clickable first and then you can click on it. XPATH, "//input[#id='password']")) pw.submit() # if this doesn't work try the I am using selenium for Python and for some reason, I get the error below Safari() browser.get('https://www.supremenewyork.com/shop/jackets/h90p8mrfk') sleep(2) In this tutorial you’ll learn advanced Python web automation techniques: using Selenium with a “headless” browser, exporting the scraped data to CSV files, and wrapping your scraping code in a Python class. Motivation: Tracking Listening Habits. Suppose that you have been listening to music on bandcamp for a while now, and you find
- Check id is in frame or not
- I have updated my chromedriver as @DebanjanB and @yong suggested. It is now version 2.39, but I still get the same error as before. The code from @stanjer answer works, but because the element is being found by css selector, it is just as slow as finding it by xpath. As far as i can tell, the only difference between
find_element_by_xpath("//input[@id='order_billing_name']")is that in the second, the program is also making sure the element found is an input. Could this have to do with the problem? if so, is there a faster way to search for it?