String folder_element_id=folder_name.getAttribute("id"); // reach the folder
WebElement file_table=webdriver.findElement(By.id(folder_element_id.replaceAll("name","table"))).findElement(By.tagName("table")); // this would table me to the html table which contains all files under this folder. All tables that hold the files under a folder have been names in such a way that replacing the string "name" in the folder name with "table" would take me to the table
WebElement file_table_body=file_table.findElement(By.tagName("tbody")); // the table body contains files and their attributes
The tbody would contain the string - "High" or "Medium" or "Low" for each file and would be named using the file name; i.e. if the file name is file-name-hello.pdf, the access string would be file-access-hello.pdf, i.e. I need to substitute file-name- with file-access- and I get the id for the access string within the tbody. This can be done with a string function in Java but the output would be a Java variable name. How would I use the Java variable name in a By.cssSelector?
WebElement access_element = file_table_body.findElement(By.cssSelector("td[id=< I should put the Java variable name here>]");
What is the syntax for the cssSelector parameter?
Thanks,
}
The following should help.
String fooLocator; //lets assume this is your locator.
WebElement access_element = file_table_body.findElement(By.cssSelector("td[id=" + fooLocator + "]");
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/zcPY_ZcS018J.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
<div id="table-container"> // A table for all files within a folder
<div id="accordion">
<div>
<table id="folder-header-15229" class="dir-folder-table">
<thead class="align_left">
<th class="folder-name" id="folder-name-15229">Financial</th>
</thead>
</table>
</div>
// Get list of folders
public static List<WebElement> getFolderList(WebDriver webdriver) {
WebElement folder_table_container=webdriver.findElement(By.cssSelector(
"div[id='table-container']"));
List<WebElement> folder_list=folder_table_container.findElements(By.cssSelector(
"th[id^='folder-name-']"));
return folder_list;
}
// Get a random folder from folder list
public static WebElement getRandomFolderElement(WebDriver webdriver) {
List<WebElement> folder_list=getFolderList(webdriver);
if(folder_list.size()==0)
return null;
else {
int i = new Random().nextInt(folder_list.size());
return folder_list.get(i);
}
}
// Get list of files in a folder
public static List<WebElement> getFileList(WebDriver webdriver, WebElement folder_element) {
String folder_element_id=folder_element.getAttribute(
"id");
WebElement file_table=webdriver.findElement(By.id(folder_element_id.replaceAll(
"name", "table"))).findElement(By.tagName("table"));
WebElement file_table_body=file_table.findElement(By.tagName(
"tbody"));
List<WebElement> file_list=file_table_body.findElements(By.cssSelector(
"td[id^='file-name-']"));
return file_list;
}
// Get a random file from a given folder
public static WebElement getRandomFileElement(WebDriver webdriver, WebElement folder_element) {
List<WebElement> file_element_list = getFileList(webdriver,folder_element);
if (file_element_list.size()==0)
return null;
else {
int i = new Random().nextInt(file_element_list.size());
return file_element_list.get(i);
}
}
Given a random file I get from getRandomFileElement(), I also need the Access value of that file.
WebElement access_element = file_table_body.findElement(By.cssSelector("td[id=< I should put the Java variable name here>]");
Thanks,
I tried coding using absolute values; for the “Financial” folder. Here is my webdriver method:
public static void testClassAccess(WebDriver webdriver) {
webdriver.findElement(By.id("folder-name-15229")).click(); // click on Financial folder name using id
WebElement folder_table_container=webdriver.findElement(By.cssSelector("div[id='table-container']")); // Find the table-container div
WebElement folder_table=folder_table_container.findElement(By.id("folder-table-15229")); // This is the table for all files under Financial. I substitute “name” with “table” to get it when I generalize the code
WebElement folder_table_tr=folder_table.findElement(By.tagName("tbody")).findElement(By.cssSelector("tr[class='selectable']")); // Got to the tbody and then the tr element under folder_table
//WebElement test_file=folder_table_tr.findElement(By.cssSelector("td[id='file-name-865d32da_Blank.docx']")); // When I tried to print this out – it worked. System.out.println output the name of the file on the UI.
WebElement test_file_access=folder_table_tr.findElement(By.cssSelector("td[class='file-access']")); // This is not working; I get “NoSuchElementFoundException”. The class name is “center file-access”
// System.out.println(test_file.getText()); // This works. I get 865d32da_Blank.docx displayed
System.out.println(test_file_access.getText()); // This doesn’t work.
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/F_eAHjCy4-sJ.