在点Python Firefox上无法点击元素

时间:2018-03-21 13:23:37

标签: python selenium firefox

我正在使用Selenium来覆盖测试,其中用户应该单击确定每个链接等待页面加载并返回以执行与其他元素相同的操作。问题是它适用于前3个可见的元素在页面上,但其余的它失败了。我尝试过不同的ActionChains组合,send_keys Keys_SPACE,但没有运气。当然,我做错了什么但不知道还有什么可以尝试

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC, expected_conditions

from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
from selenium.webdriver.support.wait import WebDriverWait


class Video003(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.hydroshare.org/"
        self.verificationErrors = []
        self.accept_next_alert = True

def test_180320_video003(self):
    driver = self.driver
    driver.get(self.base_url + "/")
    driver.find_element_by_link_text("HELP").click()
    support_links = driver.find_elements_by_css_selector(".topic-name>div")
    links_text = []
    for l in support_links:
        links_text.append(l.text)
    for link in links_text:
        elem = driver.find_element_by_xpath("//div[contains(text(),\"{}\")]".format(link))
        elem.location_once_scrolled_into_view
        elem.click()

        WebDriverWait(driver, 4).until(
            expected_conditions.text_to_be_present_in_element(
                (By.CSS_SELECTOR, "#breadcrumb-menu-home>a"),
                "HydroShare Support"
            )
        )
        driver.back()

0 个答案:

没有答案