Reputation: 175
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
Using: selenium-java-3.141.59 chrome=74.0.3729.169 (Driver info: chromedriver=74.0.3729.6)
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...
Moved to element...
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)));
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)
Upvotes: 0
Views: 879
Reputation: 478
Use a CSS selector
ChromeDriver newDriver = new ChromeDriver(); WebDriverWait waits = new WebDriverWait(newDriver, 50);
newDriver.get("https://twitter.com/");
newDriver.findElement(By.name("session[username_or_email]")).sendKeys("[email protected]");
newDriver.findElement(By.name("session[password]")).sendKeys("Cisco_12345678");
newDriver.findElement(By.className("submit")).click();
WebElement composes = waits
.until(ExpectedConditions.visibilityOfElementLocated(By.id("global-new-tweet-button")));
composes.click();
WebElement tweets = waits.until(ExpectedConditions.visibilityOf(newDriver.findElement(By.cssSelector(
"#Tweetstorm-tweet-box-0 > div.tweet-box-content > div.tweet-content > div.RichEditor.RichEditor--emojiPicker.is-fakeFocus > div.RichEditor-container.u-borderRadiusInherit > div.RichEditor-scrollContainer.u-borderRadiusInherit > div.tweet-box.rich-editor.is-showPlaceholder"))));
tweets.click();
tweets.sendKeys("heys");
Upvotes: 1