Python Selenium. Element is not interactable - python

I am trying to fill the form on (https://all-access.wax.io). When I am using Javascript
document.getElementsByName("userName")[0].value = "Hello", then I am able to write text to a form. However, when I am using same concept in selenuim
driver.find_element_by_name("userName").send_keys("Hello"), then I am getting:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
When I am executing:
self.driver.find_element_by_name("userName")[1].send_keys("Hello") this leads to:
TypeError: 'WebElement' object is not subscriptable
I have also tried to wait until content is loaded, as well as use XPath and other selectors. I guess I am doing a simple mistake, but I can`t resolve it for several hours already.
Code to reproduce a problem:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://all-access.wax.io')
browser.find_element_by_name("userName")[1].send_keys("hello")
print()

browser.find_element_by_xpath("(//input[#name='userName'])[2]").send_keys("hello")
You want to send_keys to the second input tag and not the first.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://all-access.wax.io')
browser.find_element_by_name("userName").send_keys("hello")
print()
you are using find_element which returns a webelement and not array , use find_elements or remove the index

The approach with only name attribute did not work for me because when you are trying to access with [1] there are still two elements, so the locator is not unique.
So, I used the parent pannels visible-desktop-only-flex class and also added explicit wait.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
browser = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
browser.get('https://all-access.wax.io')
wait = WebDriverWait(browser, 15)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[#class='pannels visible-desktop-only-flex']//input[#name='userName']")))
browser.find_element_by_xpath("//div[#class='pannels visible-desktop-only-flex']//input[#name='userName']").send_keys("hello")

Related

Selenium error - it does not type my name

This is my first time using python and I have a few problems. I want to automate webex(auto join meetings) and but i cant get passed this page:https://i.stack.imgur.com/kuaLI.png (it does not type my name) and I get this error:https://i.stack.imgur.com/yPeon.png
Here are the problems i have:
Error Code
Does not Type in the box I tell it too
This is what i have written so far:
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.service import Service
service = Service(r"chromedriver.exe")
service.start()
driver = webdriver.Remote(service.service_url)
driver.get('https://meetingsemea39.webex.com/meet/pr1812997966');
driver.find_element(By.ID, "push_download_join_by_browser").click()
time.sleep (6)
driver.find_element(By.CSS_SELECTOR, ".style-name-input-19PlX > .style-input-2nuAk").click()
time.sleep (3)
driver.find_element(By.CSS_SELECTOR, ".style-name-input-19PlX > .style-input-2nuAk").send_keys("Thanashs Ntouvlis")
driver.find_element(By.ID, "guest_next-btn").click()
driver.find_element(By.CSS_SELECTOR, ".style-audio-case-3xwDo").click()
driver.find_element(By.ID, "interstitial_join_btn").click()
I am not able to find how to give you the page source code but this is the url(https://meetingsemea39.webex.com/meet/pr1812997966). Just press Join from your browser and you will be on the same page i was.
You are trying to find element by CSS_SELECTOR, but style-input-2nuAk is a class, not a CSS element.
To find elements by their class name:
driver.find_element_by_class_name("class_name")
It still does not type in the box
You are trying to find element by CSS_SELECTOR, but style-input-2nuAk is a class, not a CSS element.
To find elements by their class name:
driver.find_element_by_class_name("class_name")

Getting error:(Element not interactable) when sending keys into the input field in selenium python

I am getting error (element not interactable) when I am trying to send keys into the input field. When I am trying to only click the input filed I am able to do but when giving text it is showing error I have so many things to solve this but I am getting this error only.
My code:
from selenium import webdriver
Driver=webdriver.Chrome()
Driver=get('https://YouTube.com')
Box=Driver.find_element_by_xpath('//*[#id="search-input"]')
Box.send_keys('music') ```
The searchbar is input(id=search) in div class(search-input). Try this;
from selenium import webdriver
Driver=webdriver.Chrome()
Driver.get('https://YouTube.com')
Box=Driver.find_element_by_id('search-input').find_element_by_id('search')
Box.send_keys('music')
To send elements to the search box. First induce a wait for the element to be clickable due to page load.
Box=WebDriverWait(Driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#search")))
Box.send_keys('music')
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Try with that:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
Driver=webdriver.Chrome()
Driver=get('https://YouTube.com')
Box=Driver.find_element_by_xpath('/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div/div[1]/input')
Box.send_keys('music')

How to select a textbox using selenium in python

HTMLI want to select a textbox using XPath or any other locator, but I am unable to do so. The code is working fine for one part of the page, while it is not working using any locator for the other half of the page. I am not sure if my code is wrong or if something else is the problem.
I have attached the HTML part.
Here is my code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get('Website')
driver.implicitly_wait(50)
driver.find_element_by_xpath('//*[#id="j_username"]').send_keys("Username")
driver.find_element_by_xpath('//*[#id="j_password"]').send_keys("Password")
driver.find_element_by_xpath('//*[#id="b_submit"]').click()
driver.find_element_by_xpath('//*[#id="15301"]/div[1]/a/span').click()
driver.find_element_by_xpath('//*[#id="22261"]/a').click()
driver.find_element_by_xpath('//*[#id="22323"]/a').click()
driver.implicitly_wait(50)
driver.find_element_by_xpath('//*[#id="filterRow"]').clear()
The last line is where I am getting the following error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="filterRow"]"}
Page may have not finished rendering when you try to find the element. So it will give NoSuchElementException
Try the following method
elem = driver.find_element_by_xpath('//*[#id="filterRow"]')
if len(elem) > 0
elem[0].clear()
Hope this will help you
You can wait till the elements loads using wait -
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 20)
Filter_Row = wait.until(EC.visibility_of_element_located((By.XPATH, '//*[#id="filterRow"]')))
Filter_Row.clear()
Try the above code and see what happens.
Try below solution
wait = WebDriverWait(driver, 20)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[#id='filterRow']"))).clear()
Note: add below imports to your solution :
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
As in one of comments, you mentioned upon clicking tab a new page is opening. Can you please check if its opening in a new frame. Is so please switch to frame first where your element is using below statement:
driver.switch_to.frame(driver.find_element_by_name(name))
To navigate back to original frame you can use:
driver.switch_to.default_content()
using 'find_element_by_css_selector'
driver.find_element_by_css_selector("input")

python selenium can't interact with input element? [duplicate]

This question already has answers here:
ElementNotVisibleException: Message: element not interactable error while trying to click a button through Selenium and Python
(2 answers)
Closed 3 years ago.
I'm trying to put my name in an input field. It seems like a simple thing that selenium is built to do, but I cannot figure out what I'm doing wrong.
name = driver.find_element_by_xpath('//input[#id="signUpName16"]')
name.send_keys('Josh')
I know the driver works because I've been able to click other elements. I know the xpath is right because I copied it from chrome inspector. The error I get is
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I've seen people say to try clicking or clearing elements so I've tried that too, but that still failed.
name = driver.find_element_by_xpath('//input[#id="signUpName16"]')
name.click()
name.send_keys('Josh')
yields this for the name.click() line
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
There's a few different things that can be going wrong here. If the input is not fully loaded, then it will throw this exception if you try to send_keys before it is ready. We can invoke WebDriverWait on the input element to ensure it is fully loaded before sending keys to it:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
input = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[contains(#id, 'signUpName')]")))
input.send_keys("Josh")
If this still throws the exception, we can instead try to set the input value through Javascript:
input = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[contains(#id, 'signUpName')]")))
driver.execute_script("arguments[0].value = 'Josh';", input)
If neither of these solutions work, we may need to see some of the HTML on the page you are working with to see if there's any other issue happening here.
ElementNotInteractableException occurs when
Element is not displayed,
Element is out of screen ,
Some time element is hidden or
Behind to another element
Please refer below code to solve this issue:
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.support.ui import WebDriverWait as Wait
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
driver.set_page_load_timeout("10")
driver.get("your url")
actionChains = ActionChains(driver)
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//input[#id='signUpName16']")))
actionChains.move_to_element(element).click().perform()
Solution 2:
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//input[starts-with(#id,signUpName')]"))) # if your signUpName16 element is dynamic then use contains method to locate your element
actionChains.move_to_element(element).click().perform()

How to login popup windows?

i'm trying to login this site with selenium -python
but i can't .i read another question but i didn't get it.
how can i do it?
this my error:
enter image description here
this is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.get("https://en.gamefa.com/")
driver.find_element_by_name("loginform").submit()
driver.find_element_by_class_name("ModalBoxBody")#.submit()
time.sleep(10)
elem1 = driver.find_element_by_name("log")
elem1.send_keys("mehrdad78")
elem2 = driver.find_element_by_name("pwd")
elem2.send_keys("mehrdad78").submit()
First, Your screenshot is not giving us enough data about the error. Post the error stack trace which directs to your code.
Second, all the items have id. It would be better to use id to find elements.
Third, Click does work. Submit doesn't work on buttons. using submit on an element outside a form should throw an exception.
Fourth, Use explicit wait instead of sleep.
Try this
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
driver.get("https://en.gamefa.com/")
driver.find_element_by_id("login-form").click()
elem1 = WebDriverWait(driver,5).until(EC.visibility_of_element_located((By.ID, "user_login3")).send_keys("mehrdad78")
elem2 = driver.find_element_by_id("user_pass3").send_keys("mehrdad78")
elem3 = driver.find_element_by_id("wp-submit3").submit()

Categories

Resources