Using ruby and selenium webdriver how I can get class from "container"? - ruby

I have the following form:
<div id="PaymentInfoDivContainer" class="checkout-section-container complete">
<div class="checkout-section">
<h3 class="sheen">
<span class="step">2</span>
Payment Information
</h3>
<a class="sc-button-white edit-button" onclick="SC.Checkout.Edit(this);"
href="javascript:;">Edit</a>
<div class="checkout-section-content">
</div>
Using Ruby and selenium webdriver, how I can get (and click) on "edit-button" class ?
As I understand I have to get and store in variable id="PaymentInfoDivContainer" and then use it to find the right class. Any thoughts/ideas?
Thanks

Okay,You can go as below : CSS3 [attribute$=value] Selector
driver.find_element(:css,'a[class$="edit-button"]').click
or
driver.find_element(:css,'div#PaymentInfoDivContainer>div>a').click

Related

Telegram instant view

I need a help to solve a problem that I am facing in Instant viewr. The problem is removing a <div> from my instant view.
Tried to delete through id and class, but it does not work:
#remove:$body//div[#id="navbar-complex"]
#remove: //div[#class="navbar-complex"]
The Html of div that I want to remove (link to the page):
<div id="navbar-complex" class="scrollmenu tab-content nav nav-tabs">
<i class="bi bi-building"></i> О комплексе
The same problem with following div:
<div class="csection-item-wrap">
<div class="csection-item rco1 stat3">

Dynamic xpath using anchor tag

Can any please help me in finding the dynamic xapth?
I have tried with,
#FindBy(xpath="//a[contains(#href,’friend#/friends/myfriends/friendsrequest’)]")
public WebElement lnk_FrndsSeeAll;
Here is the HTMl code,
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>
you can following xpath, which I'm taking using text in the anchor tag
//a[contains(text(),'See all')]
See all should be constant always, then only above xpath will work
It was working fine with beloew code,
#FindBy(xpath="//a[startswith(#href,'friend#/friends/myfriends/friendsrequest')]‌​‌​")
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>
<a class="pull-right see" href="friend#/friends/myfriends/friendsrequest">See all</a>

XPath Getting child elements from html

I am trying to find the xpath for only the child of a navigation bar. The path which I am trying at the moment is //div[#class='navCol subMenus'] from this peace of HTML.
<div class="PrimaryNavigationContainer">
<div class="PrimaryNavigation">
<div class="Menu">
<div>
<span>Brands</span>
<div class="navCol">
<div>
<a class="NoLink unselectable"><span>Shop by Brand</span></a>
<div class="navCol subMenus">
<div>
<span>blah</span>
I have tried a number of Xpath syntax but none seem to work to bring up just the sub categories. Thank you for any help which you can provide.

Xpath not just getting parent of html

I am trying to find the xpath for only the parent of a navigation bar. The path which I am trying at the moment is `//a[#class='unselectable'] from this peace of HTML.
`<div class="PrimaryNavigationContainer">
<div class="PrimaryNavigation">
<div class="Menu">
<div>
<a href="http://www.blah.co.uk/brands.aspx" class="unselectable"><span>
Brands</span></a>
<div class="navCol">
<div>
<a class="NoLink unselectable"><span>Shop by Brand</span></a>
<div class="navCol subMenus">
div>
<a href="http://www.blah.co.uk/blah/catlist_bd4.htm" class="unselectable"><span>
blah</span></a>
The xpath seem to be bringing up both the top level cats and sub categories and I am because it is in both but not sure how to single of the parent from the chld. Thanks for any help which you can provide
How about //div[#class="Menu"]/div/a[#class='unselectable']? This way you avoid selecting the a in the subMenus div.

Easier way to click button in nested divs with Watir?

I'm new to Watir and I'm trying to click the following login button:
<div class="container login" style="display: table;">
<div class="left">
<div class="right">
<div class="joinbox">
<form id="form_login" class="hidden-submit" method="post">
<input type="submit" value="Submit">
<div class="header">
<div class="left">
<div class="mid">
<div class="right">
<a class="button button-red submit" href="#">Log In</a>
...
So far I'm able to access this button by going through every nested div:
b.div(:class, "container login").div(:class, "right").div(:class, "joinbox")......
and so on. Is this really the best way to access this button? I assume I'm missing something. Any help is appreciated!
If there is only one link (that looks like a button) with text Log In on the page, try this:
browser.a(:text => "Log In").click
You could also use class attribute:
browser.a(:class => "button button-red submit").click
May this work?
browser.form(id,form_login).submit
BTW: I have seen some tips said safari only support GET mode for submit.
I would try:
browser.a(:href => "#").click
Assumption - "#" is unique. may need a slash so it doesn't misinterpret the #. I used something similar when I was trying to reference a button with only a href value of "/login" e.g., browser.a(:href => "/login").click.

Resources