Adding javascript executor code to string shows error

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding javascript executor code to string shows error

sreedevivasudevan91
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.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ab6ed183-1e86-4527-b85e-2ccc234c4156%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Adding javascript executor code to string shows error

total QA
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,

On Wednesday, July 11, 2018 at 2:04:55 PM UTC+5:30, [hidden email] wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a51d35e2-c205-43e3-903a-555e0a050fa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Adding javascript executor code to string shows error

sreedevivasudevan91
In reply to this post by sreedevivasudevan91
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, [hidden email] wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c222863e-a28a-419c-a550-9a10cb0f1371%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Adding javascript executor code to string shows error

total QA
Ok even the Element is hidden you can use getText() to fetch the text. But we cannot interact with it.

On Wednesday, July 11, 2018 at 4:21:04 PM UTC+5:30, [hidden email] wrote:
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, [hidden email] wrote:
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.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/9d63680c-4178-4f9a-b62d-1b463cfa8dc1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.