I am trying to understand splinter functionalities, i tried to find on web but i couldn't found good documentation with pratical examples on splinter so i asked few questions here so that it will help beginner who are trying to learn splinter :
First i am confuse what is actual css selector in splinter , there are two method i see everywhere :
browser.find_by_css()
or
browser.find_by_css_selector()
What is the difference between them and why the second one is not working in current splinter ?
Now My original question is how to select any tag which is under any class , how to select any tag which is under any id ?
I tried to find but i found most of stackoverflow questions on a splinter on "how to select option values in dropdown" , And splinter documentation is very good but the problem is they don't have practical sufficient examples for their methods.
So if i have this html code :
<div class="medium-widget success-story-category">
<h2 class="widget-title"><span aria-hidden="true" class="icon-get-started"></span>Getting Started</h2>
<p>Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages. The following pages are a useful first step to get on your way writing programs with Python!</p>
<ul>
<li><a href="https://wiki.python.org/moin/BeginnersGuide/Programmers">Beginner's Guide, Programmers</a></li>
<li><a href="https://wiki.python.org/moin/BeginnersGuide/NonProgrammers">Beginner's Guide, Non-Programmers</a></li>
<li><a href="https://wiki.python.org/moin/BeginnersGuide/Download">Beginner's Guide, Download & Installation</a></li>
<li><a href="https://wiki.python.org/moin/BeginnersGuide/Examples">Code sample and snippets for Beginners</a></li>
</ul>
</div>
Then :
How to select
<p>
tag data by selectingclass="medium-widget success-story-category"
second : How select "href" of first
<li>
tagthird : How get text between first
<li></li>
Now if there is <class_name id="something">
like :
<nav id="mainnav" class="python-navigation main-navigation do-not-print" role="navigation">
<ul class="navigation menu" role="menubar" aria-label="Main Navigation">
<li id="about" class="tier-1 element-1 with-supernav" aria-haspopup="true">
<a href="/about/" title="" class=" current_item selected selected">About</a>
Now how to select :
<nav id="mainnav" class="python-navigation main-navigation do-not-print" role="navigation">
with id using find_by_css method (not using find_by_id)How get
<a>
link using find_by_css
I have found my answer here i am going to explain so that it will help to other programmers :
First thing
browser.find_by_css_selector()
is not working and i used find_by_css method which worked perfectly so i preferfind_by_css
method.How to select
<p>
tag data by selectingclass="medium-widget success-story-category"
We can select any class the format is :
div[class="class_name"]
ordiv[any_style_element="value"]
we can select class
class="medium-widget success-story-category"
bydiv[class="medium-widget success-story-category"]
we can select
tag by
('div[class="medium-widget success-story-category"] p')
we can also find with :
find_h=browser.find_by_css('div[class="medium-widget success-story-category last"]:nth-child(2)')
or
when html is
by using :
we can capture image which is in a class by
('div[class="image_class_name"] img')
and thenresult["href" or "src"]
example :
suppose i have to select that image then i can get it by this code :
Next question is how to select
So if i have this html code :
Then we can select href link of any
Please remember nth-child(2) in
div[class="medium-widget success-story-category last"]:nth-child(1)
doesn't select second nested div of this class instead nth-child(2) select secondmedium-widget success-story-category last
class (as you can see there are two classes with same namemedium-widget success-story-category last
) .Last answer of last question :
if there is
<class_name id="something">
:then select like