0

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)

2 Answers 2

0

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’]"
1
  • I tried that in ChroPath and it's an Invalid pattern. Can you please provide an Xpath that is valid? Aug 8, 2019 at 16:04
0

I solved the issue using ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(composeTweetCSS))));

  String tweetButtonXpath = "//button[@id='global-new-tweet-button']";
  String composeTweetCSS = "[data-index] .rich-editor.is-showPlaceholder";
  String tweetMessage = "This is my test Tweet";
  WebDriverWait wait = new WebDriverWait(driver, 50);   // Wait for 50 seconds for Tweet button to appear 

  try {
       element = wait.until(
                 ExpectedConditions.visibilityOfElementLocated(By.xpath(tweetButtonXpath)));
       element = driver.findElement(By.xpath(tweetButtonXpath));
       element.click();
       System.out.println("Found and clicked Tweet button");
       } catch ( Exception e1) {
       System.out.println("Failed to find Tweet button");
       System.out.println(e1.getMessage());
       }

       try {
/* Change here*/    element = wait.until(
                ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(composeTweetCSS))));
                System.out.println("After wait until...");
                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();
       }

Output: Found and clicked Tweet button After wait until... After element.click... Found Tweet box and typed message

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.