I am having trouble in identifying the navigation of page numbers. I have the html code like below:
<div class="t-numeric">
<span class="t-state-active">1</span>
<a class="t-link">2</a>
<a class="t-link">3</a>
<a class="t-link">4</a>
<a class="t-link">...</a>`
</div>
This is to navigate to different pages and how can selenium identify 2 or 3 or 4.
You can do it by Xpath, I don't know which language you use but in C#
var page2Locator = driver.FindElement(By.XPath("//a[.=\"2\"]"));
basically your xpath expression will be
//a[.="2"]
this is for element containing text '2' exactly
Related
i am new to programming and learning cypress with react and typescript. i have html like below,
<li>
<a class="StyledListItemContent-sc-wfozlt-l jqmJwr highlight hover link">
//should check if this <a> tag has class "highlight"
<div class="Box-sc fzjcGf"></div>
<div class="Box-sc Flex-sc-1pzo701-0">
<span>some type (some type) </span> //using this span name some type
<span style="display">...</span>
</div>
</a>
</li>
how can i check if the span element with name "some type" has <a> tag with class "highlight" using cypress.
could someone help me with this. thanks.
The span might be accessed with cy.contains() since you are looking for some text in it.
The <a> is a parent but it's two levels above, so cy.parents('a') should find it.
Then the attribute can be asserted.
cy.contains('span', 'some type')
.parents('a')
.should('have.class', 'highlight')
I want to click on below link in a page with several other links like this one.
I have tried cy.get() with a number of alternative ways. I also tried cy.contains('Content 6') but received an error.
<div class="column">
<a href="/admin/contents/109">
<div class="ui segment">
<div class="ui center aligned header">
Content 6
<div class="sub header">Add description to content packages
</div>
</div>
</div>
</a>
</div>
This was my final solution:
cy.get('a[href*="admin/contents"]').contains('Content 6').click()
I found the solution on this page and with help from user called Udo: https://docs.cypress.io/faq/questions/using-cypress-faq.html#How-do-I-get-an-element’s-text-contents
The href code gives more example on how to handle this problem then other examples for same problem.
you have to "get" the correct element to click on. in your case it could be handled like this:
// find the link with href attribute containing "admin/contents" and click it
cy.get('a[href*="admin/contents"]').click()
driver = webdriver.PhantomJS()
driver.get(url)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.find_element_by_css_selector('a.btn_more').click()
I am able to click the get more link using above code
get more
but how to click on followers link?
<div class="my_show__info">
<a class="my_show__link j_get_follow" href="javascript:;" data-follow="followers"> 90</a>
<a class="my_show__link j_get_follow" href="javascript:;" data-follow="following"> 33</a>
</div>
you can form a xpath and click on the link as mentioned below. if you want using CSS. convert the following xpath with css.
driver.findElement(By.Xpath("//div[#class='my_show__info']/a[#data-follow="followers"])).click()
I am not good with CSS but I guess following should work.
driver.find_element_by_css_selector('div[class='my_show__info']>a[data-follow='followers']').click()
Scripting Language : AngularJS
My Html Code is :
<li>
<a href="javascript:void(0)">
<label ng-if="show">MyName</label>
<i class="fa fa-pencil" ng-if="show">
<i class="fa fa-trash" ng-if="show">
<input type="text" ng-hide="show" />
</a>
</li>
this above html working in all browser excepting in IE edge..
this functionality done for , when i click on edit icon in list , label will remove and textbox will show with label value ..
its like editing list for whatever i will selected or renamed of that label value .
This html code working fine in (firefox,google chrome excepting IE9 above & Edge).
Tried it with a html validator.
Output is:
Error: The element input must not appear as a descendant of the a
element.
So basically this isn't a valid HTML, it depends on the browsers on how strict they parse your markup. So you might want to use some workarounds in your code to get the same effect you want but not using that kind of markup.
Having this route in Laravel:
Route::get('post/{id}/comments','PostCommentsController#showComments');
I'am trying to access it from an anchor html tag href attribute in a php view which works with angular to render a list of items. This is a piece of code from this view (_post_content.php):
<ul class="media-list" >
<li class="media" ng-repeat="item in items" >
<div class="media-body">
<div class="row">
<div class="col-sm-9"><h5 class="media-heading">
{{ item.title }} </h5></div>
</div>
</div>
</li>
</ul>
The new view made by the controller PostCommentsController in the method showComments, is similar to _post_content.php but it shows comments by a post id (item.id in ng-repeat).
However, for other links all over the application, even in its main layout: navbars and logo anchors, image anchors, etc; its url's are prepended by the path /post/4/comments.
For example if i click in the item 4 of _post_content.php, a link called blog in the left nav bar in the main layout, shows this as url: /post/4/comments/blog
Of course this route does not exists and breaks all the application.
Please, any clue to solve this strange behavior? Is it possible angular is causing it, though i'm not using angular routes?
Thanks for your help.
If you are using relative paths for your other links, you should prepend them with a forward slash, so instead of:
<a href="blog">
your should have:
<a href="/blog">
That way the links will be relative to the root not to the current path (which in your case is /post/id/comments).
As an alternative you could also use the base meta tag, by including this in your pages' <head>:
<base href="http://yourdomain.com/">
But be aware that there are some side effects to using base which might affect your application. Read this for more info: Is it recommended to use the <base> html tag?.