本文整理汇总了Python中selenium.webdriver.PhantomJS.find_elements_by_xpath方法的典型用法代码示例。如果您正苦于以下问题:Python PhantomJS.find_elements_by_xpath方法的具体用法?Python PhantomJS.find_elements_by_xpath怎么用?Python PhantomJS.find_elements_by_xpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.PhantomJS
的用法示例。
在下文中一共展示了PhantomJS.find_elements_by_xpath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AdvertisementAdvancedViewTests
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_elements_by_xpath [as 别名]
class AdvertisementAdvancedViewTests(LiveServerTestCase):
def setUp(self):
self.driver = PhantomJS()
self.user = User.objects.create_user('admin', '[email protected]', 'pass')
self.user.save()
self.provider = Provider(
name='provider',
user=self.user,
)
self.provider.save()
self.provider_adverts = mommy.make(Advertisement, _quantity=20, provider=self.provider)
def tearDown(self):
self.driver.quit()
def open(self, url):
self.driver.get("%s%s" % (self.live_server_url, url))
def test_side_ad_display(self):
"""
Test that the side ads display properly
"""
self.open(reverse('advertisements.views.side_ads'))
self.assertEqual(len(self.driver.find_elements_by_xpath("//a")), 4)
self.driver.find_element_by_xpath("//a[1]/img")
self.driver.find_element_by_xpath("//a[2]/img")
self.driver.find_element_by_xpath("//a[3]/img")
self.driver.find_element_by_xpath("//a[4]/img")
self.assertNotEqual(self.driver.find_element_by_xpath("//a[1]").get_attribute("href"), '')
self.assertNotEqual(self.driver.find_element_by_xpath("//a[2]").get_attribute("href"), '')
self.assertNotEqual(self.driver.find_element_by_xpath("//a[3]").get_attribute("href"), '')
self.assertNotEqual(self.driver.find_element_by_xpath("//a[4]").get_attribute("href"), '')
def test_top_ad_display(self):
"""
Test that the top ad displays properly
"""
self.open(reverse('advertisements.views.top_ad'))
self.assertEqual(len(self.driver.find_elements_by_xpath("//a")), 1)
self.driver.find_element_by_xpath("//a/img")
self.assertNotEqual(self.driver.find_element_by_xpath("//a").get_attribute("href"), '')