Discussion:
[selenium-users] Dropdown selections based on localhost file name
Resident
2018-11-24 13:11:41 UTC
Permalink
Hi!

Wanted to ask, how is it possible to make dropdown selection based on
localhost file name. Someone mentioned it's possible, but haven't found any
working solution.

Example.

dropdown contains.

<select name="beginYear" id="beginYear">
<option value="2018">2018</option>
<option value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
<option value="2014">2014</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
</select>

From localhost "C://filesfolder// i have defined file name _17.xlx

How i can tell selenium (java) to take that 17 and find similar selection
from dropdown ?.


Thanks!
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a88f5b7c-2a9f-4486-9c5a-6cf87c2ecd68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Resident
2018-11-28 15:17:28 UTC
Permalink
// get files list
String dirPath = "C://folder";
File dir = new File(dirPath);
String[] files = dir.list();
if (files.length == 0) {
System.out.println("The directory is empty");
} else {
for (String aFile : files) {
System.out.println(aFile);
}
}
//get current dropdown value.
WebElement DropdownValueBeforeSelect = driver.findElement(By.tagName("option"));
String CurrentDropDownSelections = DropdownValueBeforeSelect.getText();
System.out.println(CurrentDropDownSelections);

// open dropdown list

WebElement FirstOpenDropdown = driver.findElement(By.id("beginYear"));
Select OpenDropdown= new Select(FirstOpenDropdown);
OpenDropdown.selectByIndex(0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement FirstOpenDropdownClick = driver.findElement(By.id("beginYear"));
FirstOpenDropdownClick.click();

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

//select new company value from dropdown
WebElement SelectNewCompany = driver.findElement(By.id("beginYear"));
Select SelectValueFromDropdown= new Select(SelectNewCompany);
SelectValueFromDropdown.selectByValue(dirPath);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement ClickOnFoundCompany = ((ChromeDriver) driver).findElementByPartialLinkText(dirPath);
ClickOnFoundCompany.click();

//get dropdown value after select.
WebElement DropdownValueAfterSelect = driver.findElement(By.tagName("beginYear"));
String CurrentDropDownSelectionsAfter = DropdownValueAfterSelect.getText();
System.out.println(CurrentDropDownSelectionsAfter);

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

This part throws exception SelectValueFromDropdown.selectByValue(dirPath); therefore how i could tell for selector to take file name which was provided first from String[] files = dir.list();
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3808f9d7-ef9d-43bc-a3ff-c7ae45a7e30e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Resident
2018-11-28 15:20:20 UTC
Permalink
// get files list
String dirPath = "C://folder";
File dir = new File(dirPath);
String[] files = dir.list();
if (files.length == 0) {
System.out.println("The directory is empty");
} else {
for (String aFile : files) {
System.out.println(aFile);
}
}
//get current dropdown value.
WebElement DropdownValueBeforeSelect = driver.findElement(By.tagName("option"));
String CurrentDropDownSelections = DropdownValueBeforeSelect.getText();
System.out.println(CurrentDropDownSelections);

// open dropdown list

WebElement FirstOpenDropdown = driver.findElement(By.id("beginYear"));
Select OpenDropdown= new Select(FirstOpenDropdown);
OpenDropdown.selectByIndex(0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement FirstOpenDropdownClick = driver.findElement(By.id("beginYear"));
FirstOpenDropdownClick.click();

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

//select new Date value from dropdown
WebElement SelectNewDate = driver.findElement(By.id("beginYear"));
Select SelectValueFromDropdown= new Select(SelectNewDate);
SelectValueFromDropdown.selectByValue(dirPath);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement ClickOnFoundDate = ((ChromeDriver) driver).findElementByPartialLinkText(dirPath);
ClickOnFoundDate.click();

//get dropdown value after select.
WebElement DropdownValueAfterSelect = driver.findElement(By.tagName("beginYear"));
String CurrentDropDownSelectionsAfter = DropdownValueAfterSelect.getText();
System.out.println(CurrentDropDownSelectionsAfter);

try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}

This part throws exception SelectValueFromDropdown.selectByValue(dirPath); therefore how i could tell for selector to take file name which was provided first from String[] files = dir.list();
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/512f6887-0ecc-4e1d-a5f0-d01eb02a3152%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Venu G
2018-11-29 08:55:23 UTC
Permalink
Use regular expression to fetch the name from local dir and then identify
the relevant number and pass it to select action.
Post by Resident
// get files list
String dirPath = "C://folder";
File dir = new File(dirPath);
String[] files = dir.list();
if (files.length == 0) {
System.out.println("The directory is empty");
} else {
for (String aFile : files) {
System.out.println(aFile);
}
}
//get current dropdown value.
WebElement DropdownValueBeforeSelect = driver.findElement(By.tagName("option"));
String CurrentDropDownSelections = DropdownValueBeforeSelect.getText();
System.out.println(CurrentDropDownSelections);
// open dropdown list
WebElement FirstOpenDropdown = driver.findElement(By.id("beginYear"));
Select OpenDropdown= new Select(FirstOpenDropdown);
OpenDropdown.selectByIndex(0);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement FirstOpenDropdownClick = driver.findElement(By.id("beginYear"));
FirstOpenDropdownClick.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//select new Date value from dropdown
WebElement SelectNewDate = driver.findElement(By.id("beginYear"));
Select SelectValueFromDropdown= new Select(SelectNewDate);
SelectValueFromDropdown.selectByValue(dirPath);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement ClickOnFoundDate = ((ChromeDriver) driver).findElementByPartialLinkText(dirPath);
ClickOnFoundDate.click();
//get dropdown value after select.
WebElement DropdownValueAfterSelect = driver.findElement(By.tagName("beginYear"));
String CurrentDropDownSelectionsAfter = DropdownValueAfterSelect.getText();
System.out.println(CurrentDropDownSelectionsAfter);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
This part throws exception SelectValueFromDropdown.selectByValue(dirPath); therefore how i could tell for selector to take file name which was provided first from String[] files = dir.list();
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/8d43bd8c-5979-4f51-bf1d-dc98eeb69f82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...