我有问题,当我点击Facebook时,它不会进入窗口登录弹出窗口?
于2014年11月3日创建
@author:thinkingysuser '''
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import unittest, time
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import NoSuchElementException, NoAlertPresentException
class EcardsOp(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.maximize_window()
self.driver.implicitly_wait(20)
self.base_url = "http://www.americangreetings.com/ecards/anniversary/flowers-and-hearts-4u/pn/3280122"
self.verificationErrors = []
self.accept_next_alert = True
def test_ecardsop(self):
driver = self.driver
driver.get(self.base_url + "/")
# switch to frame
driver.switch_to.frame(driver.find_element_by_css_selector(".fb_iframe_widget > span:nth-child(1) > iframe:nth-child(1)"))
driver.find_element_by_css_selector("div.pluginButton:nth-child(1)").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException, e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
答案 0 :(得分:0)
我认为,您的css需要修改按钮才能被点击。 请替换代码
driver.find_element_by_css_selector("div.pluginButton:nth-child(1)").click()
带
driver.find_element_by_css_selector("div.pluginButton:nth-child(1) button").click()