Adding javascript executor code to string shows error

18 views
Skip to first unread message

sreedeviv...@gmail.com

unread,
Jul 11, 2018, 4:34:55 AM7/11/18
to Selenium Users
WebElement element = driver.findElement(By.id(pro.getProperty("")));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("return arguments[0].text", element);
String cartCountSearchTab = ((String) ((JavascriptExecutor) driver).executeScript("return arguments[0].text;",driver.findElement(By.id(pro.getProperty(""))))).replaceAll(" ", "");

int cartCountTab = Integer.parseInt(cartCountSearchTab);

this shows null pointer exception.

total-qa

unread,
Jul 11, 2018, 6:30:37 AM7/11/18
to Selenium Users
Hi,

We can even try to get the text without using JavascriptExecutor. What is the reason for using JSE ?

String result = driver.findElement(By.id(pro.getProperty(""))).getText();

Regards,

sreedeviv...@gmail.com

unread,
Jul 11, 2018, 6:51:04 AM7/11/18
to Selenium Users
I am using javascript executor because my id is hidden and i have to use id only.


On Wednesday, July 11, 2018 at 2:04:55 PM UTC+5:30, sreedeviv...@gmail.com wrote:

total-qa

unread,
Jul 11, 2018, 8:28:00 AM7/11/18
to Selenium Users
Ok even the Element is hidden you can use getText() to fetch the text. But we cannot interact with it.
Reply all
Reply to author
Forward
0 new messages