JavascriptExecutor设置属性功能在DOM中更新,但在GUI中不更新

时间:2019-02-24 14:09:43

标签: javascript java selenium automation

<div class="" id="searchWidgetNew"><div class="errMsg width100 fl" id="gerr"></div><div class="" id="searchWidgetCommon"><div><div class="dF justifyBetween flexWrap"><div class="col-md-11 pad0 dF width90 flexWrap justifyCenter"><div class="col-md-12 pad0 dF flexWrap brdrRd5 marginB10  fltHpySrchWrp whiteBg"><div class="dF whiteBg col-md-3 col-sm-5 alignItemsCenter brdrTpBtmLft width23"><i class="blueGrey padR5 ico18 hypflt-from "></i><input type="text" id="gosuggest_inputSrc" class="inputSrch" placeholder="From" value="" autocomplete="new-password" role="combobox" aria-autocomplete="list" aria-owns="react-autosuggest-1" aria-expanded="false"></div><!-- react-text: 165 --><!-- /react-text --><div class="dF whiteBg borderRight alignItemsCenter "></div><div class="dF whiteBg col-md-3 col-sm-5 alignItemsCenter  padL20 width23"><i class="blueGrey padR5 ico18 hypflt-destination "></i><i class="hypflt-swp fltHpySwp posAbs  ico24 blueLt curPointFlt"></i><input type="text" id="gosuggest_inputDest" class="inputSrch" placeholder="Destination" value="" autocomplete="new-password" role="combobox" aria-autocomplete="list" aria-owns="react-autosuggest-1" aria-expanded="false"></div><div class="dF whiteBg borderRight alignItemsCenter"></div><div class="dF whiteBg col-sm-5 alignItemsCenter  col-md-2 "><i class="hypflt-calendar blueGrey padR5 ico20"></i><input type="text" placeholder="Departure" readonly="" class="inputSrch curPointFlt " value=""><!-- react-text: 175 --><!-- /react-text --></div><div class="dF whiteBg borderRight alignItemsCenter"></div><div class="dF whiteBg col-md-2 col-sm-5 alignItemsCenter"><i class="hypflt-calendar blueGrey padR5 ico20"></i><input type="text" placeholder="Return" readonly="" class="inputSrch curPointFlt " value=""><!-- react-text: 180 --><!-- /react-text --><input type="hidden" id="gi_return_date" name="gi_return_date" value=""></div><div class="dF whiteBg borderRight alignItemsCenter"></div><div class="dF whiteBg fl col-sm-5 justifyBetween ht45 alignItemsCenter brdrTpBtmRt curPointFlt width20" id="pax_link_common"><span class="dF alignItemsCenter ico14 textOverflow blueGrey"><i class="hypflt-adult blueGrey padR5 ico18"></i><span id="pax_label" class="blueGrey textOverflow">1 Traveller, </span><!-- react-text: 187 -->&nbsp;<!-- /react-text --><span class="blueGrey textOverflow"> Economy</span></span><div class="paxMobile paxContainer dn"><div class="errMsg width100 fl dn"><span class="alert_msg failure_msg fl"><b class="status_info fl">ERROR: </b><span class="status_cont"></span></span></div><a href="javascript:void(0);" id="pax_close" class="icon-cancel-circle fr marginT10 marginR10 fr greyDr mobdn"></a><ul><li class="roomRow dF justifyBetween"><div class="widgetUserBlock fl"><label class="ico14 db padB5"><span>Adults</span><small class="font12Lt db padT3"> (12+ yrs)</small></label><div class="number-spinner number-spinnerFil"><button class="fl minSpin brdrTpBtmLft" id="adultPaxMinus" data-dir="dwn">−</button><input type="text" id="adultPaxBox" class="fl numbSpin" value="1"><button class="fl plusSpin brdrTpBtmRt" id="adultPaxPlus" data-dir="up">+</button></div></div><div class="widgetUserBlock fl"><label class="ico14 db padB5"><span>Children</span><small class="font12Lt db padT3"> (2-12 yrs)</small></label><div class="number-spinner"><button class="fl minSpin brdrTpBtmLft" id="childPaxMinus" data-dir="dwn">−</button><input type="text" id="childPaxBox" class="fl numbSpin" value="0"><button class="fl plusSpin brdrTpBtmRt" id="childPaxPlus" data-dir="up">+</button></div></div><div class="widgetUserBlock fl"><label class="ico14 db padB5"><span>Infant(s)</span><small class="font12Lt db padT3"> (below 2 yrs)</small></label><div class="number-spinner"><button class="fl minSpin brdrTpBtmLft" id="infantPaxMinus" data-dir="dwn">−</button><input type="text" id="infantPaxBox" class="fl numbSpin" value="0"><button class="fl plusSpin brdrTpBtmRt" id="infantPaxPlus" data-dir="up">+</button></div></div></li><li class="roomRow dF justifyBetween alignItemsCenter"><span class=" ico15 width40">Travel Class</span><div class="posRel dIF width90 alignItemsCenter"><div class="width100 "><label><!-- react-text: 226 --> <!-- /react-text --><!-- react-text: 227 --><!-- /react-text --></label><div><select class="custSelect width100 whiteBg padTB5 padLR10" id="gi_class"><option value="E">Economy</option><option value="B">Business</option><option value="F">First class</option><option value="W">Premium Economy</option></select></div></div><i class="hypflt-dropDown ico8 slectArr"></i></div></li></ul></div></div></div></div><div class="justifyCenter col-md-1 col-sm-12 dF padLR0"><button class="fb button orange large ht45 fltHpySrchBtn" value="Search" type="submit" id="gi_search_btn">SEARCH</button></div></div><div class="dF width100"></div></div><div class="dF alignItemsCenter white padTB20 ico13 width100" style="transition: margin 500ms ease 0s;"><div class="dF"><span class="fltHmFltr curPointFlt " id="nonStop">Non-Stop</span><span class="fltHmFltr curPointFlt " id="student_fare_check"> Student Fare</span></div><div class="hypFltErr"><span class="alert_msg failure_msg dF brdrRd5"><b class="status_info fl">ERROR: </b><span class="status_cont red ico13">Please enter a valid Source</span></span></div></div></div></div>

我正在尝试自动化Goibobo网站中的搜索功能。对于出发,我们需要选择一个日期。我为此使用了Javascript Executor Set Attribute。属性值在DOM中使用“设置属性”进行了更新,但是GUI并未使用更新后的值进行更新。因此,当我单击“搜索”时,它说,请选择出发日期。有人可以帮我吗?

这是我已经显示的代码-`

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");`

0 个答案:

没有答案