如何使用硒在请求中发送隐藏参数

How to send hidden parameters in the request using selenium

如何使用 selenium 在请求中发送隐藏参数。 这些参数对最终用户不可见,但作为 http 请求的一部分。而我的 selenium 脚本无法模拟。因此我无法从服务器获取结果。任何建议

TravelMultiController.ajaxSearchResult(302) | search:org.travel.model.Search@cf021a8[
      originlocation=Indira Gandhi Airport(DEL) near Delhi in India
      destinationlocation=Chhatrapati Shivaji International Airport(BOM) near Mumbai in India
      originlocationcode=DEL
      destinationlocationcode=BOM
      departuredatetime=2015-05-12
      returndatetime=2015-05-13
      cabin=Economy
      adt=1
      cnn=0
      inf=0
      prefered_airline=
      originlocationcity=Delhi
      destinationlocationcity=Mumbai
      destinationCountry=India
    ] memberId: 2800000101
    [SIB] 2015-03-20 13:43:08,269 INFO - TravelManagerImpl.airSearch(405) | called..org.travel.model.Search@cf021a8[
      originlocation=Indira Gandhi Airport(DEL) near Delhi in India
      destinationlocation=Chhatrapati Shivaji International Airport(BOM) near Mumbai in India
      originlocationcode=DEL //(not able to replicate)
      destinationlocationcode=BOM  //(not able to replicate)
      departuredatetime=2015-05-12
      returndatetime=2015-05-13
      cabin=Economy
      adt=1
      cnn=0
      inf=0
      prefered_airline=
      originlocationcity=Delhi
      destinationlocationcity=Mumbai
      destinationCountry=India
    ]

我无法发送这两个参数 originlocationcode=DEL destinationlocationcode=BOM 在我的请求中。请建议一些解决方法来做到这一点。

selenium 不支持。

您可以通过编写 javascript 函数使其工作,该函数通过 WebDriver 上的 executeScript 方法从当前浏览器会话发送此请求。

请记住,Selenium 的目的是模拟真实用户,而不是发送后端请求。您可能会在 JMeter 中找到更合适的工具,或者通过编写自己的接口来发送诸如此类的请求。

如果身份验证 cookie 是您尝试在 Selenium 中执行此操作的原因 - WebDriver.manage().getCookies() 将帮助您解决这个问题。你可以把cookies拉出来扔到request里。