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
Related
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 :)
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)
I have a JavaScript code embedded in a Java method to retrieve properties of any element clicked upon in a web page.
That is, I navigate to a specific URL by creating an instance of Selenium WebDriver from my Java application and click on an object in the page that gets loaded. After the single click on the object, a HTML page opens listing the name, type, id, class name etc. associated to that object as a radio button group. I select one option from the list and click on OK. What I wanted to know is, can I push the selected data from the HTML back onto my Java application on the click event on the HTML?
Any help appreciated! Thanks! :)
WebElement interface of selenium Webdriver gives a method
getAttribute which provides value of a given attribute of the desired html element.
I hope this method is what you are looking for.
USAGE:
String field_value;
field_value = driver.findElement(By.xpath("xpath Locator")).getAttribute("attribute name")
The information which you want to get should be in any of the attribute associated to that element.
Similarly if you want all attributes associated with the element in one go you can use something like this :
((JavascriptExecutor)driver).executeScript("return arguments[0].attributes);", element);
The above will give you a comma separated list of all attributes on which you can apply your coding logic to separate them and get the corresponding values using loops.
I have two fields in a webpage. Both are composite primary keys. Out of that when I select one field (eg. out of a list of countries I select - India), the second field should display all the values corresponding to the previous field (eg. after selecting India I should get all the states in another drop-down menu).
I'm implementing this using JSP and Ajax.
Can someone please help me with this or send me the code snippets.?
Neal,
There are various codes available like this. Just do googling.
Try with link
I need to create a wizard in which the first page allows the user to select the type of the element to create, and the following pages create and set-up the selected type. In several aspects it is similar to the standard New Wizard (File->new...) but I need more control on what's happening.
How can I do that? Does there is any tutorial about that?
I see three options on how to achieve this:
Override the getNextPage(...) function of Wizard
or
Add the remaining pages to the wizard just-in-time. That is, after the user has selected what type of element to create.
or
Make the remaining wizard pages dynamic in such a way that they have different contents depending on what kind of element is being created
I recommend the first option.