How to use className method of org.openqa.selenium.By class

Best Selenium code snippet using org.openqa.selenium.By.className

Source:ReflectionBackedDriverSupplier.java Github

copy

Full Screen

...49 }50 // Cover your eyes51 private Class<? extends WebDriver> mapToClass(Capabilities caps) {52 String name = caps == null ? "" : caps.getBrowserName();53 String className;54 if (BrowserType.CHROME.equals(name)) {55 className = "org.openqa.selenium.testing.drivers.TestChromeDriver";56 } else if (BrowserType.OPERA_BLINK.equals(name)) {57 className = "org.openqa.selenium.testing.drivers.TestOperaBlinkDriver";58 } else if (BrowserType.FIREFOX.equals(name)) {59 if (isInDevMode()) {60 className = "org.openqa.selenium.testing.drivers.SynthesizedFirefoxDriver";61 } else {62 className = "org.openqa.selenium.firefox.FirefoxDriver";63 }64 } else if (BrowserType.HTMLUNIT.equals(name)) {65 if (caps.is(SUPPORTS_JAVASCRIPT)) {66 className = "org.openqa.selenium.htmlunit.JavascriptEnabledHtmlUnitDriverTests$HtmlUnitDriverForTest";67 } else {68 className = "org.openqa.selenium.htmlunit.HtmlUnitDriver";69 }70 } else if (BrowserType.IE.equals(name)) {71 className = "org.openqa.selenium.ie.InternetExplorerDriver";72 } else if (BrowserType.SAFARI.equals(name)) {73 className = "org.openqa.selenium.safari.SafariDriver";74 } else {75 // The last chance saloon.76 className = System.getProperty("selenium.browser.class_name");77 }78 if (className == null) {79 log.fine("Unsure how to create: " + caps);80 return null;81 }82 try {83 return Class.forName(className).asSubclass(WebDriver.class);84 } catch (ClassNotFoundException e) {85 throw new RuntimeException(e);86 }87 }88}...

Full Screen

Full Screen

Source:Avtorizacia.java Github

copy

Full Screen

...41 logger.info("Открыта страница Dot-Dot");42 String login = "1234567890";43 String password = "0a202de290";44 String locator = "header-login";45 driver.findElement(By.className(locator)).click();46 driver.findElement(By.name("login")).sendKeys(login);47 driver.findElement(By.id("password")).sendKeys(password);48 driver.findElement(By.id("password")).sendKeys(ENTER);49 driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);50 driver.findElement(By.className("mobile-logged")).click();51 driver.findElement(By.xpath("//*[@id=\"header\"]/div[1]/ul[2]/li[1]/ul/li[1]/a")).click();52 driver.findElement(By.className("edit-profile")).click();53 driver.findElement(By.xpath("/html/body/section/div/div/div/div[3]/div[1]/div/input")).sendKeys(COMMAND,"A","\b");54 driver.findElement(By.xpath("/html/body/section/div/div/div/div[3]/div[1]/div/input")).sendKeys("МарьИванна");55 //скролл до нужного объекта56 Object webElement = driver.findElement(By.className("btn-default"));57 ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", webElement);58 Thread.sleep(500);59 driver.quit();60 driver.get(cfg.url());61 String login = "1234567890";62 String password = "0a202de290";63 String locator = "header-login";64 driver.findElement(By.className(locator)).click();65 driver.findElement(By.name("login")).sendKeys(login);66 driver.findElement(By.id("password")).sendKeys(password);67 driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);68 driver.findElement(By.className("mobile-logged")).click();69 driver.findElement(By.xpath("//*[@id=\"header\"]/div[1]/ul[2]/li[1]/ul/li[1]/a")).click();70 //сравнить поле71 }72}...

Full Screen

Full Screen

Source:MainPage.java Github

copy

Full Screen

...14import org.openqa.selenium.support.ui.WebDriverWait;15public class MainPage extends AbstractPage{16 private final Logger logger = LogManager.getRootLogger();17 private final String MAIN_URL = "https://www.21vek.by/";18 @FindBy(className = "userToolsToggler")19 private WebElement userAccountButton;20 @FindBy(id = "selen-7anxb49cjn")21 private WebElement signInFormButton;22 @FindBy(className = "selen-pokdbn5820x")23 private WebElement signInButton;24 @FindBy(xpath = "//*[@name='email']")25 private WebElement inputLoginField;26 @FindBy(xpath = "//*[@name='password']")27 private WebElement inputPasswordField;28 @FindBy(xpath = "//*[text()='Выход']")29 private WebElement signOutButton;30 private By currentUserEmailLocator = By.className("userToolsSubtitle");31 private By popUpElement = By.id("react-popup");32 public MainPage(WebDriver driver) {33 super(driver);34 PageFactory.initElements(this.driver, this);35 }36 @Override37 public MainPage openPage() {38 driver.navigate().to(MAIN_URL);39 logger.info("Main page opened");40 return this;41 }42 public MainPage openUserTools(){43 try {44 new WebDriverWait(driver, WAIT_TIMEOUT_SECONDS)...

Full Screen

Full Screen

Source:YourAccount.java Github

copy

Full Screen

...15 super(webDriver);16 PageFactory.initElements(getWebDriver(),this);17 }18 Actions action = new Actions(webDriver);19 @FindBy(className = "icon-building")20 private WebElement myAddresses;21 @FindBy(className = "icon-user")22 private WebElement personalInformation;23 @FindBy(className = "account")24 private WebElement accountName;25 @FindBy(xpath = "/html[1]/body[1]/div[1]/div[1]/header[1]/div[3]/div[1]/div[1]/div[6]/ul[1]/li[2]/a[1]")26 private WebElement dresses;27 @FindBy(xpath = "/html[1]/body[1]/div[1]/div[1]/header[1]/div[3]/div[1]/div[1]/div[6]/ul[1]/li[2]/ul[1]/li[1]/a[1]")28 private WebElement casualDresses;29 public String getAccountNameText(){30 return getAccountName().getText();31 }32 public MyAddresses clickMyAddresses(){33 getMyAddresses().click();34 new WebDriverWait(getWebDriver(), 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("page-subheading")));35 return new MyAddresses(getWebDriver());36 }37 public MyPersonalInformation clickMyPersonalInformation(){38 getPersonalInformation().click();39 new WebDriverWait(getWebDriver(), 5).until(ExpectedConditions.visibilityOfElementLocated(By.id("email")));40 return new MyPersonalInformation(getWebDriver());41 }42 public void hoverOver(){43 action.moveToElement(getDresses()).build().perform();44 }45 public CasualDresses clickCasualDresses(){46 getCasualDresses().click();47 return new CasualDresses(getWebDriver());48 }...

Full Screen

Full Screen

Source:bbcradio.java Github

copy

Full Screen

...42 43 @Given("^I can see the radio nav$")44 public void I_can_see_the_radio_nav()45 {46 driver.findElement(By.className("radionav__stations-link radionav-dropdown")).isEnabled();47 driver.findElement(By.className("radionav__categories-link radionav-dropdown")).isEnabled();48 driver.findElement(By.className("radionav__schedules-link radionav-dropdown")).isEnabled();49 }50 51 @Given("^When I select \"([^\"]*)\" in the radio nav$")52 public void When_I_select_section_in_the_radio_nav(String Stations,String Categories,String Schedules)53 {54 driver.findElement(By.linkText(Stations)).click();55 driver.findElement(By.linkText(Categories)).click();56 driver.findElement(By.linkText(Schedules)).click();57 }58 59}...

Full Screen

Full Screen

Source:JavaScriptExecutorTest.java Github

copy

Full Screen

...4import org.openqa.selenium.support.ui.WebDriverWait;5import org.testng.annotations.Test;6import ru.levelup.qa.at.selenium.AbstractSeleniumBaseTest;7import ru.levelup.qa.at.utils.Sleep;8import static org.openqa.selenium.By.className;9import static org.openqa.selenium.By.cssSelector;10import static org.openqa.selenium.By.linkText;11import static org.openqa.selenium.By.name;12import static org.openqa.selenium.By.xpath;13import static org.openqa.selenium.support.ui.ExpectedConditions.elementToBeClickable;14import static org.openqa.selenium.support.ui.ExpectedConditions.invisibilityOfElementLocated;15import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;16import static org.testng.Assert.assertTrue;17public class JavaScriptExecutorTest extends AbstractSeleniumBaseTest {18 @Test19 public void testJsExecutor() {20 WebDriverWait wait = new WebDriverWait(driver, 5);21 driver.navigate().to("http://users.bugred.ru/");22 wait.until(elementToBeClickable(xpath("//a/span[text()='Войти']"))).click();23 wait.until(visibilityOfElementLocated(name("login"))).sendKeys("khda91@gmail.com");24 wait.until(visibilityOfElementLocated(name("password"))).sendKeys("1234");25 wait.until(elementToBeClickable(cssSelector("[value='Авторизоваться']"))).click();26 WebElement userDropdown = wait.until(visibilityOfElementLocated(className("dropdown-toggle")));27 assertTrue(userDropdown.isDisplayed());28 JavascriptExecutor jse = (JavascriptExecutor) this.driver;29 jse.executeScript("arguments[0].click();", userDropdown);30 Sleep.sleep(3000);31 wait.until(elementToBeClickable(linkText("Выход"))).click();32 assertTrue(wait.until(invisibilityOfElementLocated(className("dropdown-toggle"))));33 Sleep.sleep(3000);34 }35}...

Full Screen

Full Screen

Source:ViewAccessMenu.java Github

copy

Full Screen

...9 private final WebDriver driver;10 public ViewAccessMenu(WebDriver driver) {11 this.driver = driver;12 new WebDriverWait(driver, 10)13 .until(ExpectedConditions.elementToBeClickable(By.className("mat-menu-content")));14 }15 public void goToAccessLink() {16 WebElement link = getAccessLink();17 String href = link.getAttribute("href");18 driver.get(href);19 }20 public WebElement getAccessLink() {21 return driver.findElement(By.xpath(".//*[@data-se = 'access-btn']"));22 }23 public void closeMenu() {24 driver.findElement(By.className("mat-menu-content")).click();25 }26 public boolean accessRequestFailed() {27 try {28 return getError().isDisplayed();29 } catch (NoSuchElementException nse) {30 return false;31 }32 }33 public WebElement getError() {34 return driver.findElement(By.className("error-container"));35 }36}...

Full Screen

Full Screen

Source:MyAddresses.java Github

copy

Full Screen

...10 public MyAddresses(WebDriver webDriver){11 super(webDriver);12 PageFactory.initElements(getWebDriver(),this);13 }14 @FindBy(className = "account")15 private WebElement accountName;16 @FindBy(className = "page-subheading")17 private WebElement aliasAddress;18 public String getAliasAddressText(){19 return getAliasAddress().getText();20 }21 public YourAccount returnToYourAccount(){22 getAccountName().click();23 new WebDriverWait(getWebDriver(),5).until(ExpectedConditions.visibilityOfElementLocated(By.className("icon-building")));24 return new YourAccount(getWebDriver());25 }26 public WebElement getAliasAddress(){ return aliasAddress; }27 public WebElement getAccountName(){ return accountName; }28}

Full Screen

Full Screen

className

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.support.ui.ExpectedConditions;2import org.openqa.selenium.support.ui.WebDriverWait;3import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6public class ClassNameLocator {7 public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\User\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 driver.manage().window().maximize();11 WebDriverWait wait = new WebDriverWait(driver, 10);12 WebElement searchField = driver.findElement(By.className("gLFyf"));13 searchField.sendKeys("Selenium");14 wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("gNO89b")));15 WebElement searchButton = driver.findElement(By.className("gNO89b"));16 searchButton.click();17 Thread.sleep(5000);18 driver.quit();19 }20}

Full Screen

Full Screen

className

Using AI Code Generation

copy

Full Screen

1WebDriver driver = new FirefoxDriver();2WebElement searchBox = driver.findElement(By.className("gsfi"));3searchBox.sendKeys("Selenium");4searchBox.submit();5driver.quit();6WebElement searchBox = driver.findElement(By.className("gsfi"));

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful