本文整理汇总了Python中selenium.webdriver.PhantomJS.find_element_by_css_selector方法的典型用法代码示例。如果您正苦于以下问题:Python PhantomJS.find_element_by_css_selector方法的具体用法?Python PhantomJS.find_element_by_css_selector怎么用?Python PhantomJS.find_element_by_css_selector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.PhantomJS
的用法示例。
在下文中一共展示了PhantomJS.find_element_by_css_selector方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_start_again
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_element_by_css_selector [as 别名]
def on_start_again(self, url):
driver = PhantomJS()
driver.get(url)
time.sleep(2)
driver.maximize_window()
t = driver.find_element_by_css_selector('.page-txt').text
res_t = []
if t:
t = int(t.split('/')[1][:-1]) - 1 # get the page count
# the count of page turning should be i-1
while t:
t -= 1
move_ele = driver.find_element_by_css_selector('#next')
ActionChains(driver).move_to_element(move_ele).click()
time.sleep(1)
res_t.append(driver.page_source)
driver.quit()
for item in res_t:
self.step_first(item)
示例2: catalog_url
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_element_by_css_selector [as 别名]
def catalog_url(url='http://www.meitun.com/'):
# catalog_url is AJAX,use phantomJS
driver = PhantomJS()
driver.get(url)
driver.maximize_window()
mov_ele = driver.find_element_by_css_selector('.nav>ul>li:nth-child(1)')
# the mouse move to the lazy layout element,and perform
ActionChains(driver).move_to_element(mov_ele).perform()
time.sleep(3)
response = driver.page_source
driver.quit()
# use pyquery parser the page source,more quickly
d = pq(response)
return map(lambda x: 'http:' + pq(x).attr('href'), d.find('.cg-pdts a'))
示例3: onegoogolePR
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_element_by_css_selector [as 别名]
def onegoogolePR(self, url):
'''返回单个PR'''
prUrl = 'http://pr.chinaz.com' # 谷歌PR查询地址
driver = PhantomJS()
driver.get(prUrl)
driver.find_element_by_id('PRAddress').send_keys(url)
driver.find_element_by_class_name('search-write-btn').click()
try:
imgsrc = driver.find_element_by_css_selector('span#pr>img').get_attribute('src')
pr = search(r'\d', imgsrc).group()
except:
pr = '暂无数据'
driver.quit()
return pr
示例4: Client
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_element_by_css_selector [as 别名]
class Client(object):
"""Client HTTP pour tester fonctionnellement Strass
Adapteur du pilote Selenium, avec une interface inspirée de Nightwatch.js,
et quelques paramètres spécifiques à Strass."""
def __init__(self):
self.driver = PhantomJS()
self.driver.set_window_size(1120, 550)
def __del__(self):
self.driver.quit()
def get(self, query=None):
server = os.environ.get('STRASS_TEST_SERVER', 'http://localhost:8000')
url = server + (query or '/')
self.driver.get(url)
return self
def find(self, selector):
return self.driver.find_element_by_css_selector(selector)
def click(self, selector):
self.find(selector).click()
return self
def fill(self, selector, value):
if isinstance(value, datetime.date):
self.fill(selector + ' input.day', str(value.day))
self.fill(selector + ' input.month', str(value.month))
self.fill(selector + ' input.year', str(value.year))
else:
control = self.find(selector)
try:
control.clear()
except selexc.InvalidElementStateException:
# On doit tenter de nettoyer un input[type=file]. On zap.
pass
control.send_keys(value)
return self
def select(self, selector, value):
Select(self.find(selector)).select_by_value(value)
return self
def submit(self, selector='#document button[type=submit]'):
return self.click(selector)
def close(self):
self.driver.close()
if self.driver.window_handles:
self.driver.switch_to.window(self.driver.window_handles[0])
self.driver.set_window_size(1120, 550)
return self
def screenshot(self, filename):
self.driver.get_screenshot_as_file(filename)
sys.stderr.write("Capture d'écran enregistrée dans %r\n" % (filename,))
return self
def save(self, filename):
with open(filename, 'w') as fo:
fo.write(self.driver.page_source)
sys.stderr.write("HTML enregistré dans %r\n" % (filename,))
return self
def __getattr__(self, name):
return getattr(self.driver, name)
示例5: ProviderAdvancedViewTests
# 需要导入模块: from selenium.webdriver import PhantomJS [as 别名]
# 或者: from selenium.webdriver.PhantomJS import find_element_by_css_selector [as 别名]
class ProviderAdvancedViewTests(LiveServerTestCase):
def setUp(self):
self.driver = PhantomJS()
self.user = User.objects.create_user('admin', '[email protected]', 'password')
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)
self.login()
def tearDown(self):
self.driver.quit()
def open(self, url):
self.driver.get("%s%s" % (self.live_server_url, url))
def login(self):
self.open(settings.LOGIN_URL)
self.driver.find_element_by_id("id_username").send_keys("admin")
self.driver.find_element_by_id("id_password").send_keys("password")
self.driver.find_element_by_css_selector("button.btn.btn-default").click()
self.assertEqual(
self.driver.current_url,
self.live_server_url + reverse('advertisements.views.view_provider_statistics', args=[self.provider.pk]),
)
def test_can_login(self):
"""
Test that the user can login
"""
pass
def test_provider_page_has_all_data(self):
"""
Test that the provider statistics page has all the correct data
"""
self.open(reverse('advertisements.views.view_provider_statistics', args=[self.provider.pk]))
self.assertEqual("Open Ads", self.driver.title)
self.assertIn(
"{0} advertisements".format(self.provider.name),
self.driver.find_element_by_css_selector("h1.page-header").text
)
self.assertIn(
"{0} advertisements in rotation".format(20),
self.driver.find_element_by_css_selector("h1.page-header").text
)
def test_advertisement_page_has_all_data(self):
"""
Test that the advertisement page has all the correct data
"""
for advert in self.provider_adverts:
self.open(reverse('advertisements.views.view_advert_statistics', args=[advert.pk]))
self.assertIn(
"ID number: {0}".format(advert.pk),
self.driver.find_element_by_css_selector("h1.page-header").text,
)
self.driver.find_element_by_css_selector("img")
self.assertEqual("Active", self.driver.find_element_by_xpath("//td[2]/span").text)
self.assertEqual(advert.url, self.driver.find_element_by_link_text(advert.url).text)
self.driver.find_element_by_link_text("Edit URL").click()
self.assertEqual(advert.url, self.driver.find_element_by_id("id_url").get_attribute("value"))