P C PIOTRUSIO
P C PIOTRUSIO

Reputation: 7

Why xpath doing nothing?

source code of login bar

    BasicConfigurator.configure();
    System.setProperty("webdriver.chrome.driver","C:\\Users\\Piotrek\\projekciki\\src\\main\\java\\selenium\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("https://twitter.com/login?lang=pl");
    WebElement element = driver.findElement(By.xpath("/html/body/div/div/div/div[2]/main/div/div/form/div/div[1]/label/div/div[2]/div/input"));
    element.sendKeys("LOGIN");

just opening twitter and doing nothing. where is the problem?

Upvotes: 0

Views: 46

Answers (1)

Amruta
Amruta

Reputation: 1166

Modified code

BasicConfigurator.configure();   System.setProperty("webdriver.chrome.driver","C:\\Users\\Piotrek\\projekciki\\src\\main\\java\\selenium\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.navigate("https://twitter.com/login?lang=pl");
    WebDriverWait wait = new WebDriverWait(driver, 10);   
 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[contains(@name,'username_or_email')]")));
        WebElement element = driver.findElement(By.xpath("//input[contains(@name,'username_or_email')]"));
        element.sendKeys("LOGIN");

if above xpath doesn't work use this one-//input[contains(@name,'username_or_email' )and (@type='text')]

Upvotes: 1

Related Questions