0

I have a multiple drop-downs and need to automate them.

I added the code below, how do I add them in one step?

or

make it easier

or

how do I add them in one function?

I'm using eclipse and TestNG plugin with selenium and maven dependencies

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;

public class InstallationPage extends CreateNewStore {
@FindBy(id ="is-selling")
WebElement firstSelection;

@FindBy(name="setting[selling_channels][]")
WebElement secondSelection;

@FindBy(id = "products-select")
WebElement thirdSelection;

@FindBy(id = "range-select")
WebElement fourthSelection;

@FindBy(id= "industry-select")
WebElement fifthSelection;

@FindBy(xpath = "//input[@value='Yes']")
WebElement firstRadio;

@FindBy(xpath = "//input[@value='No']")
WebElement seondRadio;


public void InstallationSteps() 
{ 
Select selectObject = new Select(firstSelection); 
selectObject.selectByIndex(2);
 Select selectObject = new Select(secondSelection); 
selectObject.selectByIndex(3); 
Select selectObject = new Select(thirdSelection);
 selectObject.selectByIndex(2); 
Select selectObject = new Select(fourthSelection);
 selectObject.selectByIndex(2); 
Select selectObject = new Select(fifthSelection); 
selectObject.selectByIndex(2);

} }

1 Answer 1

1

Why do you need to have local variables? You can simply act on the objects

new Select(firstSelection).selectByIndex(2);
new Select(secondSelection).selectByIndex(2);
...

Or you can have a list:

List selects = Arrays.asList(new Select(firstSelection), new Select(secondSelection), ...);
selects.stream().forEach(select -> select.selectByIndex(2))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.