I have some links that are not buttons, each row of the table result has one link called View :
<a class="view-link" aria-label="View" href="/applicant_submissions/8">
<i aria-hidden="true" title="View" class="glyphicon glyphicon-folder-open icon-spacing"></i>
Can you please show me how to use Selenium using Ruby to click on this link?
Use this code:
driver.find_element(:class, "view-link").click
I don't know Ruby so, please, find my solution in Python.
You can use these locators:
Using class name:
driver.find_element_by_class_name('view-link').click
Or
Using XPath:
driver.find_element_by_xpath("//a[#href="/applicant_submissions/8']").click
Related
I am trying to click on a image link with a Capybara / Rspec test. I am having very little success at the moment.
I am trying to select the link with href "/post/3", (knowing that they are other links before). I have tried many combinations of xpath without success. The only combination working was
page.first(:xpath, //a).click
however when I have changed the file and added more links above my Capybara test is broken.
<div class='row'>
<img id="imagen3" src="/system/posts/images/000/000/003/original/frankie-mannings-102nd-birthday-5160522641047552-hp.gif?1464448829" alt="Frankie mannings 102nd birthday 5160522641047552 hp" />
<p>caption</p>
</div>
How can I select that link, and click it?
ok I got it:
find(:xpath, "//a[contains(#href,'posts/3}')]").click
//a[contains(#href, 'posts/3’)]
I'm writing selenium test for a wicket application and having trouble to get some xpaths.
For example:
I'm trying to get the xpath for a link. Here is the the link created by the wicket dynamically:
<span>
<a id="id2b3" href="#" onclick="var wcall=wicketAjaxGet('./participante_geral?7-1.IBehaviorListener.0-containerDiv-frameSetDiv-gridDiv-linhas-body-rows-1-cells-2-cell-linkPanel',function() { }.bind(this),function() { }.bind(this), function() {return Wicket.$('id2b3') != null;}.bind(this));return !wcall;">
<span>Some String</span>
</a>
</span>
I'm trying to get the xpath for the link like this:
//a/span[(text() = 'Some String')]/..
But when I run my selenium test the WebDriver for firefox, I can't locate the element/link.
When I run
$x("//a/span[(text() = 'Some String')]/..")
in chromium console I can locate the element with success.
But when I run the same command in firefox I get an array containing the link.
What is wrong with my xpath?
Thanks in advance.
Try to follow the following syntax when creating a xpath
//tagname[#attribute='value']
Try to use contains function-
//a[#id='id2b3']/span[contains(text(), 'Some String')]
Wicket supports rendering an extra attribute to each component for this use case, see IDebugSettings#setOutputComponentPath(boolean) [1]. This will render wicketpath attribute. You can use it like: //a/[#wicketpath='grand:parent:child:id'].
This is for Wicket 1.5.x/6.x.
For Wicket 7.x+ there is DebugSettings#setComponentPathAttributeName(String). If it is non-null then Wicket will use this String as a name for the attribute, e.g. data-wicket-path.
https://github.com/apache/wicket/blob/wicket-1.5.x/wicket-core/src/main/java/org/apache/wicket/settings/IDebugSettings.java#L39
Perhaps I have to manage with bad HTML programming (check here).
In below code <i> doesnt represent a word in italics but an icon. Which I want to click but which WATIR is suitable for this?
I went to this post and I tried button and image methods but none worked.
I tried it by creating its page object (as it is the way I want it to be).
button(:attendees_list, :title => 'attendees') and image(:attendees_list, :title => 'attendees')
used it as
on(UpcomingWebinarPage).attendees_list
<a class="webinar" href="javascript:;">
<i class="icon" title="attendees"></i>
<span class="number">12</span>
</a>
In page-object, you'd want to create a generic element. Because this is a strange case, I would use XPath to identify it.
element(:attendees_list, :i, xpath: "//i[#title='attendees']")
And click it with:
page.attendees_list_element.click
I think, you can try to use element :
b.element(:title, 'attendees').click
Can some one help me to locate an element (without using xpath) which is displayed using : <i id="ext-gen759" class="icon-tool"></i> under a <div> tag. The HTML is as follows:
<div id="ext-comp-1089" class=" MiniTbar">
<a href="javascript:void(0);" id="ext-gen760" class=" active">
<i id="ext-gen759" class="icon-tool"></i> -->> need to locate this.
</a>
</div>
I don't want to use:
By.Id --> id is dynamic
By.XPath --> not stable
I have tried the following without getting a result:
By.className("icon-tool") -- > not working
By.partialLinkText("icon-tool") --> not working
Any solution?
You can rely on the part of the id using, for example, starts-with():
//div[starts-with(#id, "ext-comp-")]/a[starts-with(#id, "ext-gen")]/i[#class="icon-tool"]
Or a CSS selector:
div[id^=ext-comp-] a.active[id^=ext-gen] i.icon-tool[id^=ext-gen]
using xpath should do this. You may need to make sure that's the only element i with same criteria on the page
//i[contains(#id,'ext-gen')]
Give a chance to the find element by css selector ?
driver.find_element_by_css_selector('i.icon-tool')
The python documentation is here http://selenium-python.readthedocs.org/en/latest/locating-elements.html
You can find it using css selector:
driver.findElement(By.cssSelector("i[class='icon-tool']"));
I have radio buttons that are located inside a table, such as:
<tr id="radiofield-1080-inputRow">
<td class="x-form-item-body" id="radiofield-1080-bodyEl" colspan="3">
<input type="button" id="radiofield-1080-inputEl" class="x-form-field" autocomplete="off">
<label id="radiofield-1080-boxLabelEl" class="x-form-cb-label">My Label</label>
</td>
</tr>
I do find the input element, by the following code:
xPath = String.format("//tr/td[contains(#id,'%s')][contains(label,'%s')]/label", xType, text);
webElement = webDriver.findElement(By.xpath(xPath));
but isSelected() or click() doesn't seem to work on it.
Do you have any suggestion?
Haven't used selenium in a while but from a quick google it looks like you should try the isChecked and check/uncheck methods.
Here's the Javadoc but for some reason can't get a decent link, obviously check on the Selenium object. If you're using a different version or if I misunderstood something sorry.
http://selenium.googlecode.com/git/docs/api/java/index.html
In your code snippet problem with locator.
Use any of the below below locators
By.cssSelector("input[id*='radiofield-']");
By.id("radiofield-1080-inputEl")
By.xpath("//tr/td[contains(#id,'radiofield-')]/input")
Try clicking on the "input" instead of the "label".
xpath of input:
"//input[#id='radiofield-1080-inputEl']"
If the input id is not always the same, you can try this, the location of input will be based off the label:
//label[text()='My Label']/preceding-sibling::input
Thanks for all your answers.
My finding concluded with the following:
ExtJS implement radiobutton and checkbox as button, therefore the selenium isSelected() is not functioning.
There is a need to implement isSelected(), as suggested at:
How to check if extjs checkbox is selected in selenium?
The click() does the work, as it is a button.
Thanks again, Michal