Skip to content

Instantly share code, notes, and snippets.

@borodicht
Created December 4, 2024 15:51
Show Gist options
  • Save borodicht/1994a360b96daaf60b4fe16061efec82 to your computer and use it in GitHub Desktop.
Save borodicht/1994a360b96daaf60b4fe16061efec82 to your computer and use it in GitHub Desktop.
package wrappers;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class Picklist {
WebDriver driver;
WebDriverWait wait;
String label;
String pickListPattern = "//label[text()='%s']//ancestor::lightning-picklist";
public Picklist(WebDriver driver, String label) {
this.driver = driver;
this.label = label;
wait = new WebDriverWait(driver, Duration.ofSeconds(10));
}
public void select(String option) {
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath(String.format(pickListPattern + "//button", label)))));
driver.findElement(By.xpath(String.format(pickListPattern + "//button", label)))
.click();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", driver.findElement(By.xpath(String.format(pickListPattern + "//lightning-base-combobox-item//span[text()='%s']",
label, option))));
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath(String.format(pickListPattern + "//lightning-base-combobox-item//span[text()='%s']",
label, option)))));
driver.findElement(By.xpath(String.format(pickListPattern + "//lightning-base-combobox-item//span[text()='%s']",
label, option))).click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment