I'm working in a for loop, picking up on a value in the far left column of a table and from there want to select the corresponding link in the far right column. The far right column contains 3 links.
The link 'names' are not unique and the href attributes are variable.
I have used the command;
String Amend = driver.findElement(By.xpath("//tr[" + v + "]/td[9]/a[1]")).getAttribute("href");
...to store the href attribute to the variable Amend and want to then select the link by the variable name, is this possible?
I have tried Amend.click(); and also driver.findElement(etc.......).click;, but Eclipse has flagged these as being incorrect.
Thanks in anticipation.
Amend.click() won't work because it's just a string.
If you want to open the link you should navigate to url by driver.navigate().gotourl(Amend)
Related
New to Selenium-TestNG-Java
I'm trying to find an number on a webtable and click it, as I want to be able to pick the correct number on the list. Or get the location of said number so I can select that row by clicking the first element.
This is the one I need to "pinpoint"
But the only thing I have is the Xpath ( //*[#id="multisujetoSociosTable"]/tbody/tr/td[5]/b ) and inside it is the number I need "< b >33210266801< / b >"
Any idea or tip?
Thanks for any answer.
Did you try using an xpath using text() to check the containing text?
//*[#id="multisujetoSociosTable"]/tbody//tr/td[text()='33210266801']
you could also combine with contains:
//*[#id="multisujetoSociosTable"]/tbody//tr/td[contains(text(),'33210266801')]
Like mentioned above 'get.text()' should to the trick
I want to perform below scenario.
1) I enter a name using sendkeys() and then click on search button.
2) Once I get the search results, I need to click on name which i searched for.
How do I verify and click using selenium webdriver Java.
Its a href="/cc/name.html" target = "_blank">Name.c James/a
As Saad said you could add 2 controls to be sure of the results is what you are expecting
Check only 1 eleent of the expected result is in the page. (Maybe you need to find inside some specific container first)
From that webElement compare the name
getDriver().findElements(By.tagName("a")).size() == 1
&& getDriver().findElements(By.tagName("a")).get(0).getText().equals("Name.c James/a")
If your search result is unique. Only 1 record will exist. If you are clicking on name, I'm assuming that it will redirect user to the next screen. So, get the relative xpath of the name and use click() .
Thanks :)
Well...I think I still haven't figured out how xpath works. I am trying to select the below element so that I can click on the second page. But what I am trying does not work. What is wrong here? I am selecting the a tag and then trying to find the one which contains ref whose value is next.
element = driver.findElement(By.xpath("//a[contains(#ref,'next')]"));
I probably see a typo there. The attribute you are trying to use is rel which has value next
So the correct xpath will be
//a[contains(#rel,'next')]
I am new to Selenium testing, I am trying to put the value into the textbox with the help of xpath, name & id. (java using eclipse IDE):
driver.findElement(By.xpath(".//* [#id='txtEmpDepAddressLine1']")).sendKeys("2nd Main")
driver.findElement(By.xpath(".//*[#id='txtEmpDepAddressLine2']")).sendKeys("Bangalore");
While running, textbox is not retrieve the from the above code. Can anyone help me out to solve this problem?
Use By.id instead By.xpath
If you insist xpath then:
Start with: // instead: .//
Make sure the id value is unique on page.
if using xpath in some browsers id or ID makes differnce.
It is difficult to say without the HTML, but I'd suggest a few things:
Open your page, go to the Google Chrome DevTools console, and verify you can locate the element using your xpath. So you'd type:
$x("//* [#id='txtEmpDepAddressLine1']")
and verify the text box is located.
If the sendKeys isn't working on the element at that id, I'd wonder if it is not on the text field itself, but on a containing table or something like that. Make sure the element located by the id is the input, so the sendKeys will work.
By
In the text box it is fetching the value but it can't able not store
in the text box field
do you mean you can see selenium typing those values into the textbox and then the values disappear?
If that is what is happening, it is possible there is some javascript running on the page while selenium is entering the values in the textbox. you can try to put a wait before selenium enters the value. If waiting resolves the issue, you will need to write a method to detect when the javascript is done.
Automation Specification- Java based WebDriver
Hi
i'm working on a webdriver automation(Java code) to automate bus booking. Here is my scenario....
(1)give Departure & Destination - DONE
(2) Pick the Date - DONE
(3)Search Bus -DONE
(4)View Seats & Select- I Struck here
Now as a search result, i got a list of buses with the option to view the seats.
the list of buses are shown in a dynamic-DataTable which contains an image called 'view seat' in each row. A click on the viewseat-image will give me the seat-layout where i can select the seats. found the viewseat-images are having different id's & the same class name. Now i need to locate and click on the viewseat-image whichever i want, using its id.
But the situation is
* the data table is dynamic, So the id's keep changing which doesn't allow me to locate it by a static id.
* id is the only unique thing in that coding to differentiate the viewseat-image from another. so i can locate it only if i get the id correct.
Now my idea is to, get the runtime id's of all viewseat-images, using the unique class name and store in variables and use the id's to locate the element.
So let me know if there any possibility to get the id's of all images in that data table, using the class name.
You can use absolute path and take the location of the seat which will reduce your efforts, to take the absolute path you can install a plug-in in firefox called "firepath", after installtion you will have an option for selecting either AbsolutePath or RelativePath. With the absolute path you need not use ID to identify the element which is created dynamically. The path is identified using the location of the elements within the tags.
Example for Absolute Path:
//div/div/div/table/tbody/tr/td[2]/div/input[3]
List<WebElement> elements = driver.findElements(By.className("classname"));
for(WebElement ele : elements) {
System.out.println(ele.getAttribute("id"));
}
driver.findElement(By.xpath("//a[text()='View seats']")).get(index).click()
You can try this method.But i'm not sure it can work out.I'm looking for a general way which can solve the problem at dynamic pages.
Here when the dynamic-Data Table is coming so you can store the size of in the table, Like :
int size = driver.findElements(By.xpath("//*[#id='demo_ID']/tbody/tr")).size();
And can set a loop which would read every available row of the table or you can click on them one by one. Like :
String strGetContent = text.getText();
or
text.click(); // As per your need
Now you can read or click every row of the table, although rows are coming dynamically.I hope it helped you!
For more explanation or an example I would prefer: How to Automate a Dynamic page through Selenium Web Driver