I am trying to select a dropdown value which is inside a frame. This is the code
This is how we write for a link with in frame but i am unable to select a value from dropdown
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("right"));
WebElement el1 = wait.until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Text")));
el1.click();
First, wait for the correct frame (according to HTML code, the name of the frame is main_b
)
Next, you don't have a link there ( <a>
tag), so By.partialLinkText
cannot be used. Use By.name("field")
instead
Finally, instead of clicking on it, get a Select
object: Select mySelect = new Select(el1);
and choose one of its options using selectByVisibleText
, selectByValue
or selectByIndex
method
So all together looks like this:
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("main_b"));
Select mySelect = new Select(
wait.until(
ExpectedConditions.elementToBeClickable(
By.name("field")
)));
// Select second option by visible text
mySelect.selectByVisibleText("Bacon Anna");
// Same option selected by value
mySelect.selectByValue("16344");
// Same option selected by index
new Select(el1).selectByIndex(1);
Try below code:
WebElement fr = driver.findElement(By.name("main_b"));
driver.switchTo().frame(fr);
WebElement dropdown = driver.findElement(By.name("field"));
Select sel = new Select(dropdown);
sel.selectByValue("<Value to be selected>");
You can also use wait commands if your page takes some time to load. Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.