.net App.Config文件在Selenium c中未按预期工作#

.net App.Config文件在Selenium c中未按预期工作#,.net,selenium,automation,automated-tests,.net,Selenium,Automation,Automated Tests,我正在尝试对常用值使用app.config,但无法将这些值输入浏览器。就我的代码而言,它很好,没有问题,根据我之前的研究,但是它只是返回值,但不在浏览器URL中使用它 测试中的代码: string URL=ConfigurationManager.AppSettings[“URL”].ToString() App.config: 配置是坐在通常的等,所以我知道它不是因为大小写敏感的错误 给定的app.config如下所示: <configuration> <appSe

我正在尝试对常用值使用app.config,但无法将这些值输入浏览器。就我的代码而言,它很好,没有问题,根据我之前的研究,但是它只是返回值,但不在浏览器URL中使用它

测试中的代码:
string URL=ConfigurationManager.AppSettings[“URL”].ToString()

App.config:


配置是坐在通常的等,所以我知道它不是因为大小写敏感的错误

给定的app.config如下所示:

<configuration>
    <appSettings>
        <add key="browser" value="chrome" />
    </appSettings>
    <connectionStrings>
        <add name="SeleniumServerUrl" connectionString="http://some.url/" />
    </connectionStrings>
</configuration>
ConfigurationManager.AppSettings["browser"]
var uri = new Uri(ConfigurationManager.ConnectionStrings["SeleniumServerUrl"].ConnectionString)
…和“SeleniumServerUrl”如下所示:

<configuration>
    <appSettings>
        <add key="browser" value="chrome" />
    </appSettings>
    <connectionStrings>
        <add name="SeleniumServerUrl" connectionString="http://some.url/" />
    </connectionStrings>
</configuration>
ConfigurationManager.AppSettings["browser"]
var uri = new Uri(ConfigurationManager.ConnectionStrings["SeleniumServerUrl"].ConnectionString)

请注意,您需要指定尝试获取app.config的哪个部分(上述示例中的ConnectionString/AppSettings)。

创建“testhost.dll.config”文件,而不是保存在app.config中,并将文件属性配置为“始终复制”。这会起作用。

因此您将值分配给
URL
变量。你能把代码贴在你使用这个变量的地方吗?如果你只是给它赋值,而从不使用变量,那么这就是你的问题。我认为这并不像上面说的那么简单,我现在需要做什么才能在我的Chrome驱动程序中使用这个URL@Gregburghardty您应该检查文档:请同时阅读。我有一个错误,但我知道您的目的,谢谢。@CalAtk请告诉我缺少什么,我将编辑我的答案。别忘了为社区做贡献:)当然,让我弄明白这一点,我会告诉你最新情况;首先,将值添加到下面的
AppSettings
中,后面的
Runtime
如下所示:@CalAtk您的评论毫无意义,我认为您的一些文本没有包括在内: