简体   繁体   English

关于使用 selenium c# 的会话超时

[英]Regarding Session Timeout using selenium c#

My Application has a Functionality which takes time to load the search results like more then a minute because of which my scripts fails and gives a 60 seconds session timeout error message.我的应用程序有一个功能,它需要时间来加载搜索结果,例如超过一分钟,因此我的脚本失败并给出 60 秒会话超时错误消息。 I googled few solutions and got one from stack overflow" How to set session timeout in web.config " but i am not sure where exactly to implement it.我在谷歌上搜索了几个解决方案,并从堆栈溢出中得到了一个“ 如何在 web.config 中设置会话超时”,但我不确定在哪里实现它。 i have a file in my framework called "app.config" and the code in the app.config is below我的框架中有一个名为“app.config”的文件,app.config 中的代码如下

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This Below mentioned code is given in the stack overflow to make necessary changes in web.config file to set the session timeout下面提到的代码在堆栈溢出中给出,以在 web.config 文件中进行必要的更改以设置会话超时

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>

please help me where to make the necessary changes in app.config file.请帮助我在 app.config 文件中进行必要的更改。

You could set an implicit wait for the driver in the following fashion:您可以通过以下方式为驱动程序设置隐式等待:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.隐式等待是告诉 WebDriver 在尝试查找一个或多个元素(如果它们不是立即可用)时轮询 DOM 一段时间。 The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.默认设置为 0。设置后,将在 WebDriver 对象实例的生命周期内设置隐式等待。

Now the only reason to use app.config is if you want to make this timeout configurable.现在使用 app.config 的唯一原因是您是否希望将此超时设置为可配置。 In which case in your app.config file you would add a section:在这种情况下,您将在 app.config 文件中添加一个部分:

<appSettings>
    <add key="driver.Timeout" value="20" />
</appSettings>

Then in your code you would do something like:然后在您的代码中,您将执行以下操作:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Int32.Parse(ConfigurationManager.AppSettings["driver.Timeout"]));

This way if you deploy your app somewhere and wanted to make the timeout configurable you would just edit your app.config file in a text editor and change the value.这样,如果您将应用程序部署到某个地方并希望使超时可配置,您只需在文本编辑器中编辑您的 app.config 文件并更改值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM