I am trying to log in to "investors.com," but to do that, I need to click on the "Sign In" button. Currently, I am using selenium to achieve this task. Sadly, I have tried everything, but nothing seems to work. I am not sure why that is the case. Maybe, the website composition is different. I am not sure. I will post the following code I am using at the moment. Any help will be appreciated. Thanks in advance!
My code:
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
import time
driver = webdriver.Chrome(executable_path="C:/SeliniumWebDrivers/chromedriver.exe")
driver.get('https://investors.com')
driver.implicitly_wait(10)
elements= driver.find_element_by_xpath('//*[@id="__next"]/div[2]/div[2]/div/div[2]/div[2]').click()
driver.quit()
The error I receive:
Traceback (most recent call last):
File "D:\stockProgram\IBD stocks\Market_condition.py", line 17, in <module>
elements= driver.find_element_by_xpath('//*[@id="__next"]/div[2]/div[2]/div/div[2]/div[2]').click()
File "C:\Users\arsal\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\arsal\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\arsal\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\arsal\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.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=104.0.5112.101)
CodePudding user response:
div
node is not clickable by default. You need to select and click its child link:
driver.find_element_by_link_text('Sign In').click()
CodePudding user response:
You also can use contains()
function. The following code is working.
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(text(),"Sign In")]'))).click()
#Imports
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC