Reputation: 13
I am getting this error:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible. or Element is not currently interactable.
element:
input class="artfld col-all-min ng-pristine ng-invalid ng-touched" formcontrolname="id" maxlength="10" placeholder="身分證字號" type="text"
code:
from selenium import webdriver
import time
from PIL import Image
from pynput.keyboard import Key,Controller
browser = webdriver.Chrome()
browser.get('https://mma.sinopac.com/SinoCard/Activity/Register?Code=TLDI')
time.sleep(0.3)
browser.find_element_by_xpath("/html/body/app-root/div/app-activity-register/div/div[2]/div/div/section/app-activity-register-verification/form/div[1]/table/tbody/tr[3]/td/input").send_keys("1234")
Question 2: How to get the element on a button within a pop-up window with python selenium after you click the red button?
element: button type="button" class="swal2-confirm swal2-styled" aria-label="" style="background-color: rgb(48, 133, 214); border-left-color: rgb(48, 133, 214); border-right-color: rgb(48, 133, 214);">確定 /button
Upvotes: 1
Views: 221
Reputation: 193088
To send a character sequence within the desired element you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following solutions:
Using CSS_SELECTOR
:
driver.get("https://mma.sinopac.com/SinoCard/Activity/Register?Code=TLDI")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.artfld.col-all-min.ng-untouched.ng-pristine.ng-invalid[formcontrolname='id']"))).send_keys("YOYO")
Using XPATH
:
driver.get("https://mma.sinopac.com/SinoCard/Activity/Register?Code=TLDI")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='artfld col-all-min ng-untouched ng-pristine ng-invalid' and @formcontrolname='id']"))).send_keys("YOYO")
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
Browser Snapshot:
Upvotes: 0
Reputation: 163
Can you use explicit wait instead of time.sleep(0.3)
as follows:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome()
# wait for an element to appear.
wait = WebDriverWait(browser, 10)
waited_element = wait.until(EC.visibility_of_element_located((By.XPATH, xpath_of_element)))
Upvotes: 0