JavascriptExecutor Set Attribute function updates in DOM but not in GUI

1,696 views
Skip to first unread message

Karthik Deepan

unread,
Feb 24, 2019, 10:27:01 AM2/24/19
to seleniu...@googlegroups.com
Hi,

I am trying to automate search functionality in Goibobo web.(https://www.goibibo.com). For Departure we need to select a date. I used Javascript Executor Set Attribute for this. Value of Attribute is updated in DOM using Set Attribute, but GUI is not updated with the updated Value. So when I click on Search, it says, please select a departure date. Can anyone help me in this.

Here is the code I have show far - `

System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
WebDriver driver =new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://www.goibibo.com/");
driver.findElement(By.xpath("//input[@id='gosuggest_inputSrc']")).sendKeys("Madurai (IXM)");
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@id='gosuggest_inputSrc']")).sendKeys(Keys.ARROW_DOWN);
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@id='gosuggest_inputSrc']")).sendKeys(Keys.ENTER);
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='gosuggest_inputDest']")).sendKeys("Chennai (MAA)");
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@id='gosuggest_inputDest']")).sendKeys(Keys.ARROW_DOWN);
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@id='gosuggest_inputDest']")).sendKeys(Keys.ENTER);
Thread.sleep(5000);
WebElement when = driver.findElement(By.xpath("//input[@placeholder ='Departure']"));
JavascriptExecutor js = (JavascriptExecutor)driver;
System.out.println("running javascript");
js.executeScript("arguments[0].setAttribute('value','Tue, 2 Jul')", driver.findElement(By.xpath("//input[@placeholder ='Departure']")));
//js.executeAsyncScript("arguments[0].setAttribute('value','Tue, 2 Jul')", driver.findElement(By.xpath("//input[@placeholder ='Departure']")));
Thread.sleep(5000);
System.out.println("ran");
driver.findElement(By.xpath("//button[@value='Search']")).click();
System.out.println("clicked on search");`
Thanks,
Karthik


I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

Karthik Deepan

unread,
Feb 25, 2019, 1:49:28 PM2/25/19
to seleniu...@googlegroups.com
Hi,

Anyone had a luck to solve this ?

Thanks,
Karthik

I’m protected online with Avast Free Antivirus. Get it here — it’s free forever.

Venu Adhi

unread,
Feb 26, 2019, 12:20:48 AM2/26/19
to Selenium Users
Date Field is readonly so if we set the value attribute also it's not displaying the value, You have to achieve this by date picker.

Karthik Deepan

unread,
Feb 26, 2019, 1:19:49 AM2/26/19
to seleniu...@googlegroups.com
Ok Thank you.  So how are we saying that date field is read only? Are you saying this after you try to enter date Manually or Any attribute in DOM that defines date field is read only. ?

--
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 selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c2175616-d719-4786-9bac-06a1f78cee4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Venu Adhi

unread,
Feb 26, 2019, 1:42:13 AM2/26/19
to Selenium Users
As you said either way we can say its readonly, by entering values in the field manually and If you check DOM properties of the object it is mentioned "readonly" - I have checked it plz refer attachment.
goibibo.png

Nikunj Parmar

unread,
Feb 26, 2019, 7:54:49 AM2/26/19
to Selenium Users
Hi Karthik,

Please try to use getElementByClassName in your javascript executor. 

Sample code worked for me: 

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementsByClassName('inputSrch curPointFlt')[0].value='Tue, 3 Jul';");

Thanks,
Nikunj

Karthik Deepan

unread,
Feb 26, 2019, 4:18:34 PM2/26/19
to seleniu...@googlegroups.com
Hi Nikunj,

I used the above code and as you said, it is setting the Date field correctly.  But when you clicked on Search, the search results are not showing for the date we set, it is showing results for Next day from today's date.  

Can you try from your end and have a look?

Thanks,
Karthik

--
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 selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Karthik Deepan

unread,
Mar 1, 2019, 1:21:52 AM3/1/19
to seleniu...@googlegroups.com
Hi Nikunj,

Did you get a chance to look into this?

Thanks,
Karthik

Nikunj Parmar

unread,
Mar 13, 2019, 7:16:11 AM3/13/19
to Selenium Users
Hi Karthik,

Apology for late reply.

If using java script it is only updating face value not the actual value, then in this case you should try to automate date time picker itself.

For example: 
If you want to select : 20190401 date as your departure date. The code will be like,

String departureDate = "20190401"
String cusromXpath ="//div[@id='fare_"+departureDate +"']";
.
.
.
//Some code 

driver.findElement(By.xpath(cusromXpath)).click();

I would also encourage you want to write your own custom locator if the usage is high.

kkav...@gmail.com

unread,
Mar 15, 2019, 12:24:27 AM3/15/19
to Selenium Users
need help on selenium as it is not sending text using send keys
Reply all
Reply to author
Forward
0 new messages