硒元素在已触发区域不可见异常 [英] Selenium Element is Not Visible Exception on Already Triggered Area
问题描述
我正在尝试在此站点上自动输入条目:https://gleam.io/jtwmn/3d-printer-giveaway
I'm trying to automate entries on a this site: https://gleam.io/jtwmn/3d-printer-giveaway
我能够成功点击在 Instagram 上访问@nexi_tech"链接,以及随后的蓝色按钮.然后我关闭出现的弹出窗口,并尝试在此处显示的文本框中填写姓名和电子邮件地址 ->我试图访问的文本框
I'm successfully able to click on the "Visit @nexi_tech on Instagram" link, and the blue button of the same that follows. I then close the popup window that appears, and try to fill in the name and email address in the text boxes shown here -> Text boxes I'm trying to access
此时我收到错误:selenium.common.exceptions.ElementNotInteractableException:消息:元素不可见
At this point I get the error: selenium.common.exceptions.ElementNotInteractableException: Message: Element is not visible
这是我第二次尝试的代码(第一次尝试已注释掉):
Here's the code for my second attempt (first attempt commented out):
# Code running on Python 2.7
from selenium import webdriver
from bs4 import BeautifulSoup
import time
import numpy as np
import pandas as pd
from selenium.common.exceptions import NoSuchElementException
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.add_extension('/Users/samer/Downloads/quickjava-2.0.6-fx.xpi')
firefox_profile.set_preference("thatoneguydotnet.QuickJava.curVersion", "2.0.6.1") # Prevents loading the 'thank you for installing screen'
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Images", 2) # Turns images off
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.AnimatedImage", 2) # Turns animated images off
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.CSS", 2) ## CSS
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Cookies", 2) ## Cookies
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Flash", 2) # Flash
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Java", 2) # Java
# firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.JavaScript", 2) ## JavaScript
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Silverlight", 2) # Silverlight
# Logging In
driver = webdriver.Firefox(firefox_profile)
driver.get("https://gleam.io/jtwmn/3d-printer-giveaway")
driver.maximize_window()
window_before = driver.window_handles[0]
time.sleep(3)
driver.find_element_by_css_selector("a.no-underline.enter-link.instagram-border.clearfix.grey-bg.default").click()
time.sleep(3)
driver.find_element_by_css_selector("a.btn.btn-info.btn-large.btn-embossed.ng-binding").click()
time.sleep(3)
window_after = driver.window_handles[1]
# Switch Windows
driver.switch_to_window(window_after)
# Close new tab after a bit
driver.close()
time.sleep(2)
driver.switch_to_window(window_before)
time.sleep(3)
#Fill In details
driver.find_element_by_xpath('//*[@id="contestant[name]"]').send_keys("John")
# Previous Test
# username = driver.find_element_by_id("contestant[name]")
# emailaddress = driver.find_element_by_id("contestant[email]")
# username.send_keys("John")
# emailaddress.send_keys("john@gmail.com")
time.sleep(5)
#Save Details
driver.find_element_by_css_selector("button.btn.btn-primary.ng-scope").click()
time.sleep(5)
print "Save Complete"
driver.quit()
print "Script Ended"
推荐答案
如果你尝试
len(driver.find_elements_by_xpath('//input[@id="contestant[name]"]'))
你会看到它返回4
!所以有3个不可见,只有一个可见input
.您可以尝试使用 index 来处理适当的元素:
you'll see that it returns 4
! So there are 3 not visible and only one visible input
. You can try to use index to handle appropriate element:
driver.find_elements_by_xpath('//input[@id="contestant[name]"]')[3].send_keys("John")
这篇关于硒元素在已触发区域不可见异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!