Example usage for org.openqa.selenium WebElement click

List of usage examples for org.openqa.selenium WebElement click

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement click.

Prototype

void click();

Source Link

Document

Click this element.

Usage

From source file:android.pages.DirectoriesPageAndroid.java

private void findElementByTextOnListAndClick(String text) {
    try {//from ww  w  .  j a v a2s. co m
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    List<WebElement> elements = findListOfElementsById(listOfElements);
    m: for (WebElement element : elements) {
        if (element.getText().equals(text)) {
            element.click();
            System.out.println("Clicked on: " + text);
            break m;
        }
    }
}

From source file:app.fynd.Pages.MajorFlowSanityPage.java

License:Open Source License

public void selectPaymentMethod(String paymentType) throws InterruptedException, MalformedURLException {

    //waitgetForPageLoadAndroid(60).until(ExpectedConditions.presenceOfElementLocated(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"co.go.fynd:id/menu_icon\")"))).isDisplayed();
    //List<WebElement> paymentcontainers=getAndroidDriver().findElements(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"co.go.fynd:id/menu_icon\")"));
    List<WebElement> paymentcontainers = paymentSelector;
    //      int size =paymentcontainers.size();
    //      paymentcontainers.get(size).s

    ScrolltoElementWithText(paymentType);
    for (WebElement webElement : paymentcontainers) {

        System.out.println(webElement.getText());
        if (webElement.getText().equals(paymentType)) {

            webElement.click();
            System.out.println("Selected the Bank");
            break;
        }// www . j a  v a  2  s  .c om

    }

    //      switch (paymentType) {
    //      case "Add new cards":{
    //         //TODO
    //         paymentcontainers.get(3).click();
    //      }
    //         
    //         break;
    //      case "ICICI":{
    //         paymentcontainers.get(4).click();
    //      }
    //         break;
    //      case "HDFC":{
    //         paymentcontainers.get(5).click();
    //      }
    //         break;   
    //         
    //      case "AXIS":{
    //         paymentcontainers.get(6).click();
    //      }
    //         break;         
    //         
    //      case "SBI":{
    //         paymentcontainers.get(7).click();
    //      }
    //         break;         
    //      case "KOTAK":{
    //         paymentcontainers.get(8).click();
    //      }
    //         break;      
    //      case "PAYTM":{
    //         paymentcontainers.get(9).click();
    //      }
    //         break;
    //      case "MOBIKWIK":{
    //         paymentcontainers.get(10).click();
    //      }
    //         break;   
    //      case "PAYUMONEY":{
    //         paymentcontainers.get(11).click();
    //      }
    //         break;
    //      case "OLAMONEY":{
    //         paymentcontainers.get(12).click();
    //      }
    //      case "FREECHARGE":{
    //         paymentcontainers.get(13).click();
    //      }
    //         break;
    //      default:{
    //         paymentcontainers.get(4).click();
    //      }
    //         break;
    //      }
    //      

}

From source file:app.Stepdefs.java

@When("^link tag by name \"([^\"]*)\" is pressed$")
public void link_tag_by_name_is_pressed(String tag) throws Throwable {
    List<WebElement> lista = driver.findElements(By.tagName("span"));
    for (WebElement element : lista) {
        if (element.getText().contains(tag)) {
            element.click();
        }//from  w  ww .  jav a2  s  . co m
    }
    Thread.sleep(2000);
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I change the language to \"([^\"]*)\"$")
public void I_change_the_language_to(String language) throws Throwable {
    WebElement select = driver().findElement(By.id("switchLanguage"));
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.getText().contains(language)) {
            option.click();
            blur(By.id("switchLanguage"));
            break;
        }// ww w . jav  a2 s  .  c o m
    }
    jqueryWait();
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I use the top search box to search for a project called \"([^\"]*)\"$")
public void I_use_the_top_search_box_to_search_for_a_project_called(String projectName) throws Throwable {
    WebElement largeTopSearchBox = driver().findElement(By.xpath("//*[@id='largeMenu']/div[4]/input"));
    WebElement mobileSearchBox = driver().findElement(By.xpath("//*[@id='smallSearchBar']/input"));
    WebElement mobileSearchButton = driver().findElement(By.id("mobileSearchButton"));

    if (largeTopSearchBox.isDisplayed()) {
        largeTopSearchBox.clear();/* w ww  . j a  v a2  s . c  o m*/
        largeTopSearchBox.sendKeys(projectName);
        largeTopSearchBox.sendKeys(Keys.RETURN);
        jqueryWait();
    } else if (mobileSearchButton.isDisplayed()) {
        mobileSearchButton.click();
        mobileSearchBox.clear();
        mobileSearchBox.sendKeys(projectName);
        mobileSearchBox.sendKeys(Keys.RETURN);
        jqueryWait();
    }
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I press the download button$")
public void I_press_the_download_button() throws Throwable {
    WebElement downloadButton = driver()
            .findElement(By.xpath("//*[@class='projectDetailsDownloadButton']/a[1]"));
    downloadButton.click();
}

From source file:authentication.AccountInfo.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

    WebDriver driver = new ChromeDriver();
    driver.get(//from w  w w .j  av  a2s  .  c o  m
            "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5");
    WebElement username = driver.findElement(By.id("email"));
    WebElement password = driver.findElement(By.id("pass"));
    username.sendKeys(b.getUserName());
    password.sendKeys(b.getPassWord());
    WebElement button = driver.findElement(By.id("loginbutton"));
    button.click();
}

From source file:authentication.TestingTable.java

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
    WebDriver driver = new ChromeDriver();
    driver.get(//from   w  w w. ja  va2 s .  c  o m
            "https://www.facebook.com/?stype=lo&jlou=Afeo3usnUHyB5AT4TqVF4PpoNba5Ld2sOALGhGMfhib8xyeI0FjYqdYf72ZtVncLyfHnYBBU6pY3XZ_l-D-KchQXCwLecdkAemJcXs_dIu-UmQ&smuh=16711&lh=Ac-txP8J-TK6lCJ5");
    WebElement username = driver.findElement(By.id("email"));
    WebElement password = driver.findElement(By.id("pass"));
    password.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 0).toString());
    username.sendKeys(model.getValueAt(jTable1.getSelectedRow(), 1).toString());
    WebElement button = driver.findElement(By.id("loginbutton"));
    button.click();
}

From source file:backend.MakeUserTest.java

@Test(description = "check if new user was succesfully added", priority = 3, dependsOnMethods = { "makeUser" })
public void validateNewUser() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    //sort descending(newest on top)
    WebElement table = driver.findElement(By.id("detailTable_person"));
    WebElement idCell = table.findElement(By.xpath("//th[text()='Id']"));
    idCell.click();
    Thread.sleep(500);//  w  w w .  j  av  a 2  s. c  o  m

    //select first table entry
    List<WebElement> tableRows = table.findElements(By.tagName("tr"));
    String userId = tableRows.get(2).findElement(By.xpath("//td[1]")).getText();
    String nameCell = tableRows.get(2).findElement(By.xpath("//td[2]")).getText();

    //validate if first entry is the new user. delete user if true, fails test if false
    if (nameCell.equals("testUser123")) {
        WebElement delete = table.findElement(By.xpath("//span[@onclick=\"dialog.deleteDialog('" + userId
                + "','person',{ refresh : 'null'}, null)\"]"));
        delete.click();
        WebElement elementConfirm = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Delete']")));
        WebElement confirm = table.findElement(By.xpath("//span[text()='Delete']"));
        confirm.click();
        WebElement elementButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]")));
    } else {
        org.testng.Assert.fail("Test user was not succesfully created.");
    }
}

From source file:basicweb.ElementDisplayed.java

@Test
public void testLetsKodeIt() throws InterruptedException {
    driver.get(baseUrl1);//from   w ww.  ja v  a 2s  .co  m

    WebElement textBox = driver.findElement(By.id("displayed-text"));
    System.out.println("Text Box Displayed: " + textBox.isDisplayed());

    Thread.sleep(3000);

    WebElement hideButton = driver.findElement(By.id("hide-textbox"));
    hideButton.click();
    System.out.println("Clicked on hide button");
    System.out.println("Text Box Displayed: " + textBox.isDisplayed());

    Thread.sleep(3000);

    // Added code to scroll up because the element was hiding behind the top navigation menu
    // You will learn about scrolling in future lecture
    js.executeScript("window.scrollBy(0, -190);");
    WebElement showButton = driver.findElement(By.id("show-textbox"));
    showButton.click();
    System.out.println("Clicked on show button");
    System.out.println("Text Box Displayed: " + textBox.isDisplayed());
}