This question already has answers here:
Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome
(1 answer)
"selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element" while clicking a 'Next' button with Selenium
(1 answer)
Selenium in Python: "NoSuchElementException: Message: no such element: Unable to locate element"
(5 answers)
Closed 2 years ago.
Is it because i using python REPL? I don't know what that is.
My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://member.lazada.com.my/user/login?spm=a2o4k.home.header.d5.1e532e7eD9UgkJ&redirect=https%3A%2F%2Fwww.lazada.com.my%2F%3Fspm%3Da2o4k.login_signup.header.dhome.7d0d49fbWgHyQw")
print(driver.title)
time.sleep(10)
driver.find_element_by_id("a2o4k.login_signup.menu.i0.128549fbdpzNIi").click()
Error code:
Lazada.com.my: Online Shopping Malaysia - Mobiles, Tablets, Home Appliances, TV, Audio & More
Traceback (most recent call last):
File "C:\Program Files (x86)\CUBAR.py", line 13, in <module>
driver.find_element_by_id("a2o4k.login_signup.menu.i0.128549fbdpzNIi").click()
File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\naufa\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="a2o4k.login_signup.menu.i0.128549fbdpzNIi"]"}
(Session info: chrome=87.0.4280.66)
You're trying to find an id that is dynamic and will change instead use either a css selector or xpath. I am assuming you are trying to click the sign up button or something similar. Here's an example of that element.
CSS SELECTORS
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.mod-login-btn > button"))).click()
XPATHS
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "button[text()='SIGN UP']"))).click()
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Related
This question already has answers here:
Selenium "selenium.common.exceptions.NoSuchElementException" when using Chrome
(1 answer)
"selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element" while clicking a 'Next' button with Selenium
(1 answer)
Selenium in Python: "NoSuchElementException: Message: no such element: Unable to locate element"
(5 answers)
Closed 2 years ago.
I have a problem when want to click on number. Using Selenium webdriver.
Here is code
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
chromedriver_location = 'chromedriver'
driver = webdriver.Chrome(chromedriver_location)
driver.get('site')
username_input = '/html/body/div[2]/div/div/form/div[1]/input'
password_input = '/html/body/div[2]/div/div/form/div[2]/input'
login_submit = '/html/body/div[2]/div/div/form/button'
driver.find_element_by_xpath(username_input).send_keys('username')
driver.find_element_by_xpath(password_input).send_keys('password')
driver.find_element_by_xpath(login_submit).click()
numbers = '/html/body/div[1]/div/div[3]/div/div[1]/div[5]/div'
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/iframe")))
driver.find_element_by_xpath(numbers).click()
This is in iFrame and need to click on number 5
Full xPath of number 5 is /html/body/div[1]/div/div[3]/div/div[1]/div[5]/div
Error message is:
Traceback (most recent call last):
File "<pyshell#25>", line 1, in
driver.find_element_by_xpath(numbers).click()
File "C:\Users\m\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\m\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\m\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\m\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div1/div/div[3]/div/div1/div[5]/div"}
(Session info: chrome=87.0.4280.88)
Also tried with
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, numbers))).click()
Error for this is
Traceback (most recent call last):
File "<pyshell#26>", line 1, in
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, numbers))).click()
File "C:\Users\m\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
switch to iframe first:
iframe=WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "/html/body/iframe")))
driver.switch_to.frame(iframe)
driver.find_element_by_xpath(numbers).click()
#REMAINING CODE TO INTERACT WITH ELEMENTS INISIDE IFRAME
#once done exit from iframe
driver.switch_to.default_content()
This question already has answers here:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable when clicking on an element using Selenium Python
(6 answers)
Closed 2 years ago.
I want to automate through python using selenium and I need help.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
Sergo=['Sergo']
driver = webdriver.Chrome()
driver.get("https://www.youtube.com/")
print(driver.title)
search = driver.find_element_by_xpath('//*[#id="search"]')
search.send_keys(Sergo)
time.sleep(5)
driver.quit()
Here is the error:
Traceback (most recent call last):
File "c:/Users/user/Desktop/bot/automation.py", line 11, in <module>
search.send_keys(Sergo)
File "C:\Users\user\Desktop\bot\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\user\Desktop\bot\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\user\Desktop\bot\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\user\Desktop\bot\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=83.0.4103.116)
Your xpath is not unique
Use this xpath:
search = driver.find_element_by_xpath('//input[#id='search']')
This is because you don't have the Chromedriver.
Click on the 3 dots at the right-top in your Chrome browser
Click on About Chrome/Chromium
Check the version mentioned in light gray
Go to the ChromeDriver [downloads page]
(https://chromedriver.chromium.org/downloads).
Download the correct version as per your browser version.
Copy the path to ChromeDriver.exe
As an argument,pass executable_path=r'path/to/chromedriver.exe'
in driver = webdriver.Chrome().
For example, mine is:
driver = webdriver.Chrome(executable_path=r'C:\Users\dell\Libs\chromedriver.exe')
I'm trying to click the "Login" button on this website, with Selenium : https://results.decisiondeskhq.com/2020/primary/colorado/president. I right clicked the element in inspect element, copied the xpath, and put it into the find_element_by_xpath function.
Here's my code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/users/aliallam/Desktop/scraper test/chromedriver")
url = 'https://results.decisiondeskhq.com/2020/primary/colorado/president'
driver.get(url)
driver.find_element_by_xpath('//*[#id="content"]/div/div/div/div/button').click()
This is the error message I get:
Traceback (most recent call last):
File "/Users/aliallam/Desktop/scraper test/sandbox2.py", line 7, in <module>
driver.find_element_by_xpath('//*[#id="content"]/div/div/div/div/button').click()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="content"]/div/div/div/div/button"}
(Session info: chrome=80.0.3987.149)
Thank you in advance!
You need to wait until the webpage load to select the button. You need to import
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
adding the delay and wait before select the element like this:
delay = 10 # seconds
WebDriverWait(driver, delay).until(
EC.presence_of_element_located((By.CLASS_NAME, 'signup-boxes')))
# you can select element that you want ini here
for more resource visit here
The element has an unique id, so instead of using xpath, you should use the id and you should apply explicit wait on the element so that the script waits until the element is present and as there is a div of element present above the element that you are trying to click, you need to use java script click in this case.
Your code should be like:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="/users/aliallam/Desktop/scraper test/chromedriver")
url = 'https://results.decisiondeskhq.com/2020/primary/colorado/president'
driver.get(url)
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "login-text-btn")))
driver.execute_script("arguments[0].click();", element)
Can't click on the download link using Selinium Webdriver
I'm trying to automate my weekly anime routes using python
from selenium import Webdriver
import time
dr = webdriver.Chrome()
time.sleep(3)
dr.get('https://horriblesubs.info/shows/one-punch-man-s2')
time.sleep(1)
link=dr.find_element_by_class_name("rls-info-container").click()
time.sleep(3)
blink=dr.find_element_by_xpath("//span[#class='dl_type hs-magnet-link']").click()
time.sleep(6)
dr.quit()
This is the error i get
Traceback (most recent call last):
File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\Scripts\get-ShieldHero.py", line 16, in <module>
blink=dr.find_element_by_xpath("//span[#class='dl_type hs-magnet-link']").click()
File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Hey\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[#class='dl_type hs-magnet-link']"}
(Session info: chrome=74.0.3729.169)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Windows NT 10.0.17134 x86_64)
I want to click on the 480 link, but I can't with the above code
I've attempted other variations where I try and inspect the html block, but I've been unsuccessful.
To click() on the link with text as Magnet for the item One Punch Man S2 you need to click the <a> node within the <span> node and you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[contains(., 'One Punch Man S2')]//following::span[#class='dl-type hs-magnet-link']/a"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
I am searching to do a program for fun but i have some problems with selenium and i
need some help...
This is the programm (i deleted the directory of webdriver because the folder's name contain the name of an other person)
from selenium import webdriver
import webbrowser
import time
def Pass_send_():
driver=webdriver.Chrome()
driver.get('chrome://flags/#password_export-enable')
ricerca=driver.find_element_by_id("search")
ricerca.send_keys('password export')
scorritore=driver.find_element_by_class_name('experiment-select')
scorritore.click()
Pass_send_()
And so the purpose it's easy, it should open a windows, type a text and click a button. everything works but the click doesn't and this is the error:
Traceback (most recent call last):
File "C:\Python34\internet22.py", line 18, in <module>
Pass_send_()
File "C:\Python34\internet22.py", line 14, in Pass_send_
scorritore.click()
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-
packages\selenium\webdriver\remote\errorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
So i am not an expert but it says: element not intercatable? what does it mean and how can i fix it? i would really appreciate a reply...
To send a character sequence to the search box within the webpage chrome://flags/#password_export-enable you need to induce WebDriverWait and you can use the following solution:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('chrome://flags/#password_export-enable')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#search"))).send_keys("password export")
Browser Snapshot: