Unable to enter text in Twitter using Selenium Webdriver



  • I'm trying to automate Tweeting using Selenium Webdriver in Chrome. I can login and click the Tweet button, opening the Compose new Tweet box, but when I try to enter text with element.sendKeys(tweetMessage); I get

    org.openqa.selenium.ElementNotInteractableException: element not interactable

    Here's the relevant code:

    String composeTweetXpath = "//div[@aria-labelledby='Tweetstorm-tweet-box-0-label Tweetstorm-tweet-box-0-text-label']//div";
    String tweetMessage = "This is my test Tweet";
    
    WebDriver driver;
    driver = new ChromeDriver();
    
    
    try {
        element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(composeTweetXpath)));
        System.out.println("After wait until...");
        element = driver.findElement(By.xpath(composeTweetXpath));
        System.out.println("After driver.findElement...");
        element.click();
        System.out.println("After element.click...");
        element.sendKeys(tweetMessage);
        System.out.println("Found Tweet box and typed message");
    } catch ( Exception e1) {
        System.out.println("Failed to find Tweet box");
        e1.printStackTrace();
    }
    

    I'm surprised that I don't get the error on element.click(); but on element.sendKeys(tweetMessage);

    My output from this snippet is :

    After wait until...
    After driver.findElement...
    After element.click...
    Failed to find Tweet box
    org.openqa.selenium.ElementNotInteractableException: element not interactable
    

    I've also tried using:

        String js = "arguments[1].value = arguments[0]; ";   
        System.out.println("Executing : " + js);
        javascript.executeScript(js, tweetMessage, element);
    

    Instead of element.sendKeys(tweetMessage); This doesn't fall into the } catch ( Exception e1) { block, but still doesn't enter the text in the Compose new Tweet box.

    Strangely enough, if I use driver = new FirefoxDriver(); I get the TimeoutException error at this line:

    element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(composeTweetXpath)));
    

    Error:

    org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //div[@aria-labelledby='Tweetstorm-tweet-box-0-label Tweetstorm-tweet-box-0-text-label']//div (tried for 10 second(s) with 500 milliseconds interval)
    


  • You can use the below-mentioned approach that we usually follow in our software testing company for automation testing services

    The XPath provided in the 'composeTweetXpath' parameter is not intractable. Created an XPath using multiple attributes to enter text in the tweet box.

    XPath for Tweet Box: "//div[@name='tweet' and @class='tweet-box rich-editor is-showPlaceholder’]"
    


Suggested Topics