How to use css_to_xpath method in SeleniumBase

Best Python code snippet using SeleniumBase

reviews_parser.py

Source:reviews_parser.py Github

copy

Full Screen

...12N_FETCH = 1513FETCH_SLEEP = 114#Navigation selectors15NEXT_PAGE = "a.next-link" #"div:last-child > span > a > span.navigation-button-icon__373c0__2Fl7a > svg"16sel_next_page = XPath(GenericTranslator().css_to_xpath(NEXT_PAGE))17BANNED_TEXT = "Sorry, you’re not allowed to access this page."18NOT_RECOMMENDED_NEXT_PAGE = "div.not-recommended-reviews div.arrange_unit > a.next"19REMOVED_NEXT_PAGE = "div.removed-reviews div.arrange_unit > a.next"20sel_unusual_activity = XPath("//*[text() = 'Unusual Activity Alert']|//*[text() = 'Public Attention Alert']")21close_unusual_activity = "//*[text() = 'Got it, thanks!']"22#Business data23#CSS selectors24sel_raw_data_container = XPath(GenericTranslator().css_to_xpath('script[data-apollo-state]')) 25rd_left_marker = b"<!--"26rd_right_marker = b"-->"27#Strings28ammenity_prefix = ".organizedProperties({\"clientPlatform\":\"WWW\"}).0.properties" #Not strictly a prefix29ammenity_keys = ["displayText","alias","isActive","iconName"]30#Recommended reviews31#CSS selectors32sel_review_container = XPath(GenericTranslator().css_to_xpath("section"))33sel_page_number = XPath(GenericTranslator().css_to_xpath('div[aria-label="Pagination navigation"] > div > span'))34sel_review_list = XPath(GenericTranslator().css_to_xpath('div.border-color--default__373c0__1WKlL > ul.undefined.list__373c0__vNxqp'))35#sel_review_list = XPath(GenericTranslator().css_to_xpath('ul.lemon--ul__373c0__1_cxs.undefined.list__373c0__2G8oH'))36sel_user_card = XPath(GenericTranslator().css_to_xpath('div.user-passport-info'))37sel_rating = XPath('descendant-or-self::div/@aria-label')38sel_elite = XPath('descendant-or-self::a[@href="/elite"]')39sel_review = XPath(GenericTranslator().css_to_xpath('p > span.raw__373c0__tQAx6'))40#sel_review_count = XPath('descendant-or-self::span[contains(@class, "icon--16-review-v2")]/..//span[2]')41sel_review_count = XPath(GenericTranslator().css_to_xpath('span.css-bq71j2'))42#sel_review_count = XPath(GenericTranslator().css_to_xpath('div:has(> span.icon--16-review-v2) > span.text__373c0__2Kxyz '))43#sel_review_count = XPath(GenericTranslator().css_to_xpath('div.photoHeader__373c0__YdvQE span.text__373c0__2Kxyz'))44sel_date = XPath(GenericTranslator().css_to_xpath('span.css-e81eai'))45sel_user_friend_count = XPath(GenericTranslator().css_to_xpath('div[aria-label="Friends"]'))46sel_user_review_count = XPath(GenericTranslator().css_to_xpath('div[aria-label="Reviews"]'))47sel_user_photo_count = XPath(GenericTranslator().css_to_xpath('div[aria-label="Photos"]'))48#Regexes49review_count_re = re.compile(r"(\d+)( reviews?)?")50rating_re = re.compile(r"(\d) star rating")51page_number_re = re.compile(r"(\d+) of (\d+)")52date_re = re.compile(r"(Updated \- )?(\d{1,2})/(\d{1,2})/(\d{4})")53#Not recommended reviews54#CSS selectors -- not recommended55sel_not_recommended_review_container = XPath(GenericTranslator().css_to_xpath("div.ysection.not-recommended-reviews.review-list-wide div.review.review--with-sidebar"))56sel_not_recommended_page_number = XPath(GenericTranslator().css_to_xpath("div.not-recommended-reviews div.page-of-pages"))57sel_not_recommended_review_count = XPath(GenericTranslator().css_to_xpath("div.ysection.not-recommended-reviews.review-list-wide > h3"))58sel_not_recommended_user_card = XPath(GenericTranslator().css_to_xpath("div.ypassport.media-block"))59sel_not_recommended_user_img = XPath(GenericTranslator().css_to_xpath("img.photo-box-img"))60sel_not_recommended_user_name = XPath(GenericTranslator().css_to_xpath("span.user-display-name"))61sel_not_recommended_user_location = XPath(GenericTranslator().css_to_xpath("li.user-location"))62sel_not_recommended_user_friends = XPath(GenericTranslator().css_to_xpath("li.friend-count > b"))63sel_not_recommended_user_reviews = XPath(GenericTranslator().css_to_xpath("li.review-count > b"))64sel_not_recommended_user_photos = XPath(GenericTranslator().css_to_xpath("li.photo-count > b"))65sel_not_recommended_rating = XPath(GenericTranslator().css_to_xpath("img[alt $= 'rating']"))66sel_not_recommended_no_rating = XPath(GenericTranslator().css_to_xpath("img[alt $= '(no rating)']"))67sel_not_recommended_date = XPath(GenericTranslator().css_to_xpath("span.rating-qualifier"))68sel_not_recommended_review_card = XPath(GenericTranslator().css_to_xpath("div.review-content"))69sel_not_recommended_content = XPath(GenericTranslator().css_to_xpath("p"))70sel_not_recommended_content_toggleable = XPath(GenericTranslator().css_to_xpath("span.js-content-toggleable.hidden"))71#Regexes72not_recommended_review_count_re = review_count_re73not_recommended_rating_re = re.compile(r"(\d).0 star rating")74not_recommended_page_number_re = re.compile("Page (\d+) of (\d+)")75#Removed reviews76sel_removed_reviews_root = XPath(GenericTranslator().css_to_xpath('div.removed-reviews'))77sel_removed_review_container = XPath(GenericTranslator().css_to_xpath("div.review.review--with-sidebar"))78sel_removed_page_number = XPath(GenericTranslator().css_to_xpath("div.page-of-pages"))79sel_removed_review_count = XPath(GenericTranslator().css_to_xpath("h3"))80sel_removed_user_card = sel_not_recommended_user_card81sel_removed_user_img = sel_not_recommended_user_img82sel_removed_user_name = sel_not_recommended_user_name 83sel_removed_user_location = sel_not_recommended_user_location 84sel_removed_user_friends = sel_not_recommended_user_friends 85sel_removed_user_reviews = sel_not_recommended_user_reviews 86sel_removed_user_photos = sel_not_recommended_user_photos 87sel_removed_rating = sel_not_recommended_rating 88sel_removed_no_rating = sel_not_recommended_no_rating89sel_removed_date = sel_not_recommended_date90sel_removed_review_card = sel_not_recommended_review_card 91sel_removed_content = sel_not_recommended_content 92sel_removed_content_toggleable = sel_not_recommended_content_toggleable 93#Regexes...

Full Screen

Full Screen

test_task_link.py

Source:test_task_link.py Github

copy

Full Screen

...29 task = self.add_task(**kwargs)30 return fromstring(task.get_link())31 def test_task_is_linked_when_user_has_access(self):32 link = self.add_task_and_get_link()33 link_tag = link.xpath(css_to_xpath('a'))[0]34 self.assertEquals(35 'http://example.com/qux/dossier-1/task-2',36 link_tag.get('href'))37 def test_task_is_not_linked_when_user_has_no_access(self):38 link = self.add_task_and_get_link(principals=[])39 self.assertEquals([], link.xpath(css_to_xpath('a')))40 # check that all the other parts are the same41 self.assertEquals('wf-task-state-tested-and-closed',42 link.xpath(css_to_xpath('span'))[0].get('class'))43 self.assertEquals('Do it!',44 link.xpath(css_to_xpath('span'))[1].text)45 self.assertEquals('(Org Unit 1 / Test User (test_user_1_))',46 link.xpath(css_to_xpath('span'))[2].text)47 def test_task_is_always_linked_when_user_has_administrator_role(self):48 self.grant('Administrator')49 link = self.add_task_and_get_link(principals=[])50 link_tag = link.xpath(css_to_xpath('a'))[0]51 self.assertEquals(52 'http://example.com/qux/dossier-1/task-2',53 link_tag.get('href'))54 def test_task_is_always_linked_when_user_has_manager_role(self):55 self.grant('Manager')56 link = self.add_task_and_get_link(principals=[])57 link_tag = link.xpath(css_to_xpath('a'))[0]58 self.assertEquals(59 'http://example.com/qux/dossier-1/task-2',60 link_tag.get('href'))61 def test_link_title_is_breadcrumb(self):62 link = self.add_task_and_get_link()63 link_tag = link.xpath(css_to_xpath('a'))[0]64 self.assertEquals(65 '[Admin Unit 1] > 0 Allgemeines > 01 SonstigesTestdossier 4tw > Testaufgabe',66 link_tag.get('title'))67 def test_link_text_is_task_title(self):68 link = self.add_task_and_get_link()69 span_tag = link.xpath(css_to_xpath('a span'))[0]70 self.assertEquals('Do it!', span_tag.text)71 def test_link_contains_contenttype_class(self):72 link = self.add_task_and_get_link()73 span_tag = link.xpath(css_to_xpath('a span'))[0]74 self.assertEquals('contenttype-opengever-task-task',75 span_tag.get('class'))76 def test_is_prefixed_with_state_icon_per_default(self):77 link = self.add_task_and_get_link()78 self.assertEqual(79 'wf-task-state-tested-and-closed',80 link.xpath(css_to_xpath('span'))[0].get('class'))81 def test_state_prefixe_is_parametrable(self):82 task = self.add_task()83 link = fromstring(task.get_link(with_state_icon=False))84 self.assertEqual(None, link.xpath(css_to_xpath('span'))[0].get('css'))85 def test_link_is_suffixed_with_responsible_info_by_default(self):86 link = self.add_task_and_get_link()87 suffix = link.xpath(css_to_xpath('span'))[2]88 self.assertEquals('(Org Unit 1 / Test User (test_user_1_))', suffix.text)89 self.assertEquals('discreet', suffix.get('class'))90 def test_responsible_info_is_parametrable(self):91 task = self.add_task()92 link = fromstring(task.get_link(with_responsible_info=False))93 self.assertEquals(94 'Do it!', link.xpath(css_to_xpath('span'))[-1].text)95 def test_fallback_when_admin_unit_not_exists(self):96 link = self.add_task_and_get_link(admin_unit_id='not-existing')97 self.assertEqual([], link.xpath(css_to_xpath('a')))98 self.assertEqual('span', link.tag)99 self.assertEqual('Do it!', link.text)100 self.assertEqual('contenttype-opengever-task-remote-task', link.get('class'))101 def test_target_blank_for_remote_tasks(self):102 link = self.add_task_and_get_link(admin_unit_id='additional')103 link_tag = link.xpath(css_to_xpath('a'))[0]104 span_tag = link.xpath(css_to_xpath('a span'))[0]105 self.assertEquals('_blank', link_tag.get('target'))106 self.assertEquals('contenttype-opengever-task-remote-task', span_tag.get('class'))107 def test_link_is_xss_safe(self):108 link = self.add_task_and_get_link(109 title="Foo <b onmouseover=alert('Wufff!')>click me!</b>")110 link_tag = link.xpath(css_to_xpath('a span'))[0]111 self.assertEquals(112 '<span class="contenttype-opengever-task-task">Foo &lt;b onmouseover=alert(\'Wufff!\')&gt;click me!&lt;/b&gt;</span>',113 tostring(link_tag))114 def test_link_breadcrumb_part_is_xss_safe(self):115 link = self.add_task_and_get_link(116 breadcrumb_title='0 Allg. > <b>4tw</b> > Task')117 link_tag = link.xpath(css_to_xpath('a'))[0]118 #INFO: link_tag.attr['titles'] automatically decodes html entities119 self.assertEquals(120 '<a href="http://example.com/qux/dossier-1/task-2" '121 'title="[Admin Unit 1] &gt; 0 Allg. &gt; &lt;b&gt;4tw&lt;/b&gt; &gt; '122 'Task"><span class="contenttype-opengever-task-task">Do it!</span>'123 '</a> ',124 tostring(link_tag))125 def test_handles_non_ascii_characters_correctly(self):126 link = self.add_task_and_get_link(title=u'D\xfc it')127 span_tag = link.xpath(css_to_xpath('a span'))[0]...

Full Screen

Full Screen

examples.py

Source:examples.py Github

copy

Full Screen

...4# pip install cssselect5from cssselect import HTMLTranslator6css_to_xpath = HTMLTranslator(xhtml=True).css_to_xpath7if __name__ == '__main__':8 xpath_expr = css_to_xpath('div#main > a[href]')9 print(xpath_expr) # descendant-or-self::div[@id = 'main']/a[@href]10 xpath_expr = css_to_xpath('div')11 print(xpath_expr) # descendant-or-self::div12 xpath_expr = css_to_xpath('table:nth-last-child(1)')13 print(xpath_expr) # descendant-or-self::table[count(following-sibling::*) = 0]14 print()15 for item in ('#title', '#head', '#heading', '.pageTitle', '.news_title', '.title', '.head',16 '.heading', '.contentheading', '.small_header_red'):17 xpath_expr = css_to_xpath(item)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful