3 matching nodes.. all have same source code ..hence it is failing //img[(#src='/PHYLINSPortlet/images/override-0.gif')]
<img id="_PHYLINSPortlet_WAR_PHYLINSPortlet_INSTANCE_o3P5_:form_PolicyContent_UI2:Messages:0:j_id1885:0:j_id897" class="null" alt="" src="/PHYLINSPortlet/images/override-0.gif" style="border:0px"/>
This is the xpath of a dynamic button:
I need to click on all the buttons.
what I did is --
List<WebElement> buttons = driver.findElements(By.xpath("//img[(#src='/PHYLINSPortlet/images/override-0.gif')]"));
for( WebElement button : buttons ) {
button.click();
}
It is little bit difficult to provide the proper solution of your problem as you haven't shared your HTML.
As I observe the image in the question. You have 3 same types of image and want to click on any specific image lets say SECOND image then you need to use xpath methods like following-sibling or preceding-sibling to make your xpath unique
Example :-
Suppose you have any unique column in your table (Rule id) or you want to click a specific image.e.g. rule id Val01014 image
Use the methods like following xpath -
//img[#src='/PHYLINSPortlet/images/override-0.gif']/preceding-sibling::td[text()='Val_01014']
OR
//img[#src='/PHYLINSPortlet/images/override-0.gif']/following-sibling::td[text()='Val_01014']
Related
I have three <div class= emploBox "> and each has a button. Buttons do not have unique names. How can I find this particular button?
I want to use class=cutTooLongTest and test 'automated tester' but I don't know how.
wants to find the button marked in yellow.
enter image description here
I have no idea for a solution
If I understood you right, you need to find the XPath for the button using the text 'automated tester'.
The XPath expression should be like this:
//h2[text() = 'automated tester']//..//button[contains(#class, 'standard Button--icon')]
this should work for you:
webDriver.findElement(By.xpath("//h2[#class = 'cutTooLongTest' and text() = 'automated tester']/following-sibling::div/button[1]"));
How can i click on this button with selenium ?
<a class="_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy" role="button" href="" ajaxify="/nux/wizard/step/?action=skip" rel="async-post" id="u_9_8">İleri</a>
Something I wish I would have figured out earlier was how to create my own advanced CSS selectors here is the page that taught me, it will work in all cases assuming your element is visible in the DOM.
https://www.smashingmagazine.com/2009/08/taming-advanced-css-selectors/
For your given element you could write this many ways
Generic form
tag[attribute='ATTRIBUTE_VALUE']
For your example
a[id='u_9_8']
or
a[class='_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy']
or
a[rel='async-post']
Now all these selectors will only be useful if the attribute is unique. But take a look at that article there are many tricks you can use to make CSS selectors work for you.
By using xpath with contains text you can click on the element(below is the answer)
driver.findElement(By.xpath("//a[contains(text(),'Ileri')]")).click();
Try it and let me know if it works for you
Try any of these below mentioned code.
Using id locator
driver.findElement(By.id("u_9_8")).click();
Using xpath locator
driver.findElement(By.xpath("//a[text()= 'İleri']").click();
Explanation:- Use text method along with <a>tag.
driver.findElement(By.xpath("//a[#role='button'][text()= 'İleri']").click();
Explanation:- Use role attribute and text method along with <a> tag.
Please add the wait conditions before you are going to click
Element clicking Via linkText :
webDriver.findElement(By.linkText("İleri")).click();
Element clicking Via id :
webDriver.findElement(By.id("u_9_8")).click();
Element clicking Via cssSelector :
1.webDriver.findElement(By.cssSelector("._42ft._4jy0.rfloat._ohf._4jy4._517h._51sy")).click();
2.webDriver.findElement(By.cssSelector("a[class='_42ft _4jy0 rfloat _ohf _4jy4 _517h _51sy']")).click();
Element clicking Via javaScript :
((JavascriptExecutor) driver).executeScript("arguments[0].click();", webElement);
Here you need to pass the element locator instead of webElement.
We can see ID attribute tag so we can use ID "u_9_8" to click on the button.
use the below code.
driver.findelement(By.id("u_9_8")).click();
I think you should be able to use the id
driver.findElement(By.id("u_9_8")).click();
Give it a shot
In firepath I saw two identical attributes, firepath has two results.
Here is the highlighted HTML code below in firebug:
<button class="list_header_search_toggle icon-search btn btn-icon table-btn-lg" style="margin-left:0px">
And below is the whole code:
<button class="list_header_search_toggle icon-search btn btn-icon table-btn-lg" style="margin-left:0px">
<span class="sr-only">Search</span>
</button>
NOTE: There is only 1 search button, I search it every where and there is only 1 but it shows two??
How to code this in selenium web driver?
The snippet from firepath:
Update:
Html code image, from firepath:
You can use XPath functions, for example:
position() returns the position of element at DOM
//button[#id='hdr_problem_task']/th[2]/button[position()=1]
last()
//button[#id='hdr_problem_task']/th[2]/button[last()]
something like first() doesn't exist, instead of this you can use index:
//button[#id='hdr_problem_task']/th[2]/button[1]
Also if button has some text you can use it as well:
//button[#id='hdr_problem_task']/th[2]/button[text()='button name']
or with contains()
//button[#id='hdr_problem_task']/th[2]/button[contains(text(), 'button name')]
UPDATE:
The button has name Search you can use XPath with - contains().
One more small suggestion, don't forget about future support. And instead of the following locator:
//*[#id='hdr_problem_task']/th[2]/button
Much better will be:
//button[#id='hdr_problem_task']/th[2]/button
You can use th tag's name attribute value in order to recognize the correct Search button, as shown below:
//th[#name='search'][1]/button/span[text()='Search']
Let me know, whether it works for you.
I'm designing tests in Selenium WebDriver Framwework and I would like to insert text into fields in login box.
Here is a website www.fitandjump-widzew.pl
After click on "Zaloguj" button in top right corner, Login box appears.
I would like to insert text into E-mail inputfield.
Here is my code:
WebElement emailInput = driver.findElement(By.xpath("//[#id=\"inputFields\"]"));
emailInput.click();
emailInput.sendKeys("grzegorzrudniak#gmail.com");
After execution I get this error:
org.openqa.selenium.ElementNotVisibleException: element not visible
Can anyone help me to insert text into this field?
Please take a look at second input in this box, it's called "Hasło".
Xpath of this two fields is the same.
Additional question is how to insert text into "Hasło" inputfield as well?
Just make sure the locator you are using identifies single element [Unique]. Use single quotes in xpath and use correct xpath, you haven't used any html tag after // I've used * which means it is valid for all HTML tags.
WebElement emailInput = driver.findElement(By.xpath("//*[#id='inputFields']"));
//emailInput.click(); // no need to click on the element, you can directly type.
emailInput.sendKeys("grzegorzrudniak#gmail.com");
I would like to get the value of all div tags specified in attached. I have tried with all possible locators like classname etc, which is showing null. and tried with JavaScript also which is returning null.
Please see the screen shot and I need the selected text which is in blue color starts with "Enables enterprise IT to deploy networking services"
You need to research creating selectors as this isn't a difficult one. There are numerous approaches for this element, but here's one for you: $$("#offers-popover .description"). Obviously this is a CSS selector based on the $$ and you use getText from the Selenium API in order to scrape the element text, which is what I assume you are intending to do.
driver.findElement(By.css("#offers-popover .description")).getText();
Since your element is not visible you can try this:
String divText = driver.findElement(By.className("description")).getAttribute("textContent");
Or, if this is not the only element on the page with the class description:
WebElement popElement = driver.findElement(By.id("offers-popover"));
String divText = popElement.findElement(By.className("description")).getAttribute("textContent");