I'm new to selenium ide and i want to automate some websites. i want it to be like this.
Click
Click Link 1
do some clicking inside that link
go back to the list of link
Click Link 2
do some clicking inside that link
go back to the list of link
Click Link 3
and so on
my only problem here is i don't know how it will click the first link from the top. this is the html of the website.
<h5>20 seconds ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
wews
send new
post **Link 1**
</li>
</ul>
<h5>3 minutes ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
yokol
submitted a new
post **Link 2**
</li>
</ul>
<h5>4 minutes ago</h5>
<ul>
<h3>6 minutes ago</h3>
<ul>
<h5>7 minutes ago</h5>
<ul>
<h2>8 minutes ago</h2>
<ul>
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png">
hey
send new
post **link 3**
</li>
</ul>
I haven't used Selenium ide, but I have used Selenium Webdriver for python which is similar
You just need to locate your element by css selector, specifically structural selectors; this is prob the easiest way if you have to dig through a lot of markup that doesn't have ids/classes
CSS has descendent selectors and psuedo-element selectors that allow you to target specific elements based solely on their position within the DOM, without needing an id or class
you can use the :nth-of-type() psuedo element, which targets the specific occurrence of that element based on the number you pass to it
for example in plain css:
a:nth-of-type(1)
would look within the body and select the a that is the first of its type. if you used 2 instead, it would target the second occurrence of an anchor.
for example, in selenium.webdriver this is how you'd find your element:
# ff is the webdriver.Firefox() instance
firstAnchor = ff.find_element_by_css_selector("a:nth-of-type(1)")
secondAnchor = ff.find_element_by_css_selector("a:nth-of-type(2)")
You can use that to target the 1st, 2nd, 3rd etc elements. There's also css attribute selectors too if you need to target an element based on a specific attribute value
ff.find_element_by_css_selector("a[href='/account/54351-wews']")
good luck mayne. cholla cholla hee haw
Related
I am new to HTML and so here is very basic question, for which unfortunately I could not find a hint any where . So I am putting it here. Basically, I have to use the tags href, and style both. How do I do it? For example, consider the following:
I have a list like this:
<ul>
<li style="color:blue;font-size:20px;text-align:justify">that is inclusive, innovative, and relevant</li>
</ul>
Now I want to have a hyperlink on the text :
that is inclusive, innovative, and relevant
For example, clicking the above text should go to google.com
How do I do this?
Here you go let me know the style is preperly applied or not.
<ul>
<li style="color:blue;font-size:20px;text-align:justify">that is inclusive, innovative, and relevant</li>
</ul>
You need to use the anchor tag <a> and set the href property to your url. The display text can go inside the element.
Visit Google
A list with two links:
<ul>
<li style="color:blue;font-size:20px;text-align:justify">
<a href="https://www.example.com">
that is inclusive, innovative, and relevant
</a>
</li>
<li style="color:blue;font-size:20px;text-align:justify">
<a href="https://www.w3.org/MarkUp/1995-archive/Elements/A.html">
Anchor tag spec
</a>
</li>
</ul>
Styles can be applied to the link or the list item. The browser does some default styling to anchor tags to make them blue and underlined, and purple after being visited. Often times this default styling is removed or overridden.
I am working on a bespoke WordPress build and for some reason, I just cannot get some anchor links to work. It's driving me potty and I just don't know what the problem is.
I have discovered, static anchor links are working fine (the back to top button works). However, I am using Advanced Custom Fields to generate ID's for the anchor tags. The IDs are generating correctly, but won't work as anchor tags.
Anyone have any ideas? The bit I am referring to is the service boxes near the bottom of the page. The idea being you click on these and that they will take you to the services page, and down to the relevant section.
The markup I am using is:
<ul class="cf">
<li>
<div>
<a href="/services/#dimensional-surveys">
<div class="filter"></div>
<img width="500" height="600" src="pexels-photo-175771-500x600.jpeg" class="attachment-feature size-feature" alt="" />
<h3>3D Dimensional Surveys</h3>
</a>
</div>
</li>
</ul>
<ul class="service-list cf">
<li id="#dimensional-surveys">
<div class="feature" style="background-image:url(pexels-photo-175771.jpeg);">
</div>
</li>
</ul>
Just remove the # from id and it will work.
<ul>
<li id="example"></li>
</ul>
I have looked at your page
The point where an ancor should jump to should have no #
You do: <li id="#dimensional-surveys">
But do just <li id="dimensional-surveys">
Fix that first and test again.
You don't want the '#' on the anchor: <li id="#example"></li> should be <li id="example"></li>
Here is the HTML of my tool. Each <li is a button for a page. Once I click the page number, that element will no longer have the child <a. So in the below example, page 2 is selected.
<span class="pagingWidget"
<ul>
<li>
<a class="paginate-page" href="javascript:;">1</a>
</li>
<li>2</li>
<li>
<a class="paginate-page" href="javascript:;">3</a>
</li>
<li>
<a class="paginate-page" href="javascript:;">4</a>
</li>
</ul>
</span>
I want to create an object that will always select the page element that is selected. So I want span.pagingWidget > ul > li, that does NOT have a child of <a. Is that possible with the negation CSS pseudo-class?
Unfortunately, what you're attempting to do is not possible through CSS alone.
The closest thing to what you're describing is the :empty pseudo class but that is used to select elements that are completely empty.
Hello I'm new to selinium ide and xpath thing, that's why I need help regarding this one. I need to click some links on a website i can make it work in 1 link I don't know how it will search and click the other link because it has different number and post title. The link look like this one.
http://imageshack.com/a/img27/328/zv17.png
post
post
post
I use this xpath and it works on first link
//div[#id='main']/ul[2]/li[1][#class='notification-posted']/a[2]
What is the right xpath that will click 1 link and the preceding links
please help me with this one
Edit
Thank you so much your first code it works but not the second one. but every post in ul is important, your code is working on the first post in ul.
<h5>20 seconds ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png" />
wews
send new
post <!--//li[#class='notification-posted'][1]/a[2]-->
</li>
</ul>
<h5>3 minutes ago</h5>
<ul>
<li class="notification-posted">
<img height="15" alt="" src="/assets/images/icons/notification-posted.png" />
yokol
submitted a new
post <!--//li[#class='notification-posted'][2]/a[2]-->
</li>
</ul>
<h5>4 minutes ago</h5>
<ul/>
<h3>6 minutes ago</h3>
<ul/>
<h5>7 minutes ago</h5>
<ul>
<h2>8 minutes ago</h2>
<ul />
<li class="notification-posted" />
<li class="notification-posted" />
<li class="notification-posted" />
<li class="notification-posted" />
<li class="notification-posted" />
<img height="15" alt="" src="/assets/images/icons/notification-posted.png" />
hey
send new
post <!--***Problem was here***-->
</ul>
that should be
//li[#class='notification-posted'][6]/a[2]
right? but it parse other link. thank you for your answer.
/ul[2]... should return the first post of the second ul
Assuming that the number of posts per ul is both variable, and also not important (i.e. you want the posts irrespective of which ul they are in), then you can bypass the ul.
If <li class='notification-posted'> uniquely identifies posts, you can reference the 3 links as follows:
(//li[#class='notification-posted'])[1]/a[2]
(//li[#class='notification-posted'])[2]/a[2]
(//li[#class='notification-posted'])[3]/a[2]
(// ... )[n]/a[2]
The a[2] is needed because you are after the second link in each instance.
If this isn't selective enough, you can add the filter that the li must also contain an img of notification-posted.png icon is always associated with the hyperlink:
(//li[#class='notification-posted'][img src="/assets/images/icons/notification-posted.png"])[1]//a[2]
and the same for links [2] and [3]
Edit
You can find all links which have the text post with the following xpath:
//a[#href][normalize-space(.)='post']
Tested on the (xhtmlized version of your html) with the following xsl:
<xsl:for-each select="//a[#href][normalize-space(.)='post']">
<Link>
<xsl:value-of select="#href"/>
</Link>
</xsl:for-each>
Gives:
<Link>/news/53235</Link>
<Link>/news/253129-loss</Link>
<Link>/news/25151-helloworld</Link>
You can find all links like this:
//a[starts-with(#href,'/news/')]
or:
//a[starts-with(#href,'/news/')]/#href
I have a weirdest thing, in this peace of code a browser adds tags automatically. I disabled all javascript and css, left only simple HTML and still see tags added. Here is my code:
<div id="menu-contact" class="menuNew">
<ul class="navi-list">
<li class="goto">Go to:</li>
<li id="whats">Welcome!</li>
<li>About</li>
<li>Shop</li>
<li><a class="active" href="#menu-contact">Contact</a></li>
</ul>
</div>
and here is what firefox4 sees:
<div id="menu-contact" class="menuNew">
<a> </a>
<ul class="navi-list">
<a>
<li class="goto">Go to:</li>
</a>
<li id="whats">
<a></a>
Welcome!
</li>
<li>
About
</li>
<li>
Shop
</li>
<li>
<a class="active" href="#menu-contact">Contact</a>
</li>
</ul>
</div>
It basically surrounds each tag by a tag. Again, I removed all js and css references..any idea what's going on?? Funny thing, that I have the same code (with unique IDs) in the same page and it renders normally.. only the last snippet adds tags..
My best guess absent a link to a live example is that there is a stray <a> somewhere above that element, and Firefox is attempting to apply it to all the elements below, and of course not having a very happy time of it. A quick HTML validation will reveal if something like that is going on, since either the <a> is unclosed (invalid) or the <ul> is inside it (also invalid).
If that doesn't explain it (which is entirely possible, since I'm just speculating wildly), consider crafting a live example we can inspect in detail. Certainly what you're describing is not normal Firefox behavior, so any clues we can get to what makes your situation different will help.