在已经触发的区域

时间:2017-06-17 11:12:04

标签: javascript python-2.7 selenium

我正在尝试自动化此网站上的条目:https://gleam.io/jtwmn/3d-printer-giveaway

我已成功点击“在Instagram上访问@nexi_tech”链接,然后点击相同的蓝色按钮。然后我关闭出现的弹出窗口,并尝试在此处显示的文本框中填写姓名和电子邮件地址 - > Text boxes I'm trying to access

此时我收到错误:selenium.common.exceptions.ElementNotInteractableException:消息:元素不可见

这是我第二次尝试的代码(第一次尝试注释掉):

# 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"

1 个答案:

答案 0 :(得分:0)

如果您尝试

len(driver.find_elements_by_xpath('//input[@id="contestant[name]"]'))

你会看到它返回4!因此,有3个不可见,只有一个可见input。您可以尝试使用索引来处理适当的元素:

driver.find_elements_by_xpath('//input[@id="contestant[name]"]')[3].send_keys("John")