通过列表框的索引强制选择或取消相同的值(Force selection by index of listbox or take apart same values)
我使用文本框和按钮将项目添加到列表框:
if (tbName.Text != "") { listBox.Items.Add(tbName.Text); //Let user add another new items tbName.Text = ""; }
并尝试选择执行某些操作的项目(因为我编辑它)。
但问题是用户可以添加相同的项目值,而当我尝试选择其中一个项目时,会导致失败。 它会自动选择两个相同名称的项目,操作不正确。
我可以使用某种方法强制列表框按索引选择项目(因为索引不应该相同)? 或者我如何通过编程分割相同的项目值(它不会选择相同的项目,只是选择我点击的内容,这是否意味着我应该通过选择项目拦截MouseDown或SelectChanged的事件参考鼠标点击的位置,像线的高度是18px,所以如果我点击的位置在18~36px之间,那么选择项的索引应该是1,0是0~18px)?
我的listBox是:
<ListBox Height="248" HorizontalAlignment="Left" Margin="141,223,0,0" Name="listBox" VerticalAlignment="Top" Width="378" />
I use textbox and button to add items to listbox:
if (tbName.Text != "") { listBox.Items.Add(tbName.Text); //Let user add another new items tbName.Text = ""; }
And try to select items doing something (as I edit it).
But the trouble is the user can add same value of item, and while I try to select one of the item, it will result in failure. It will auto-select two items by same name, and the operation will be improper.
Can I use some method to force the listbox select items by index( since the index shouldn't be same)? Or how can I take apart the same value of items by programming(it won't select same item but just select what I click, is it means I should intercept the event of MouseDown or SelectChanged by select items refer to the position of mouse click, like height of the line is 18px, so if the position I click is between 18~36px, then the index of select item should be 1, and 0 is 0~18px)?
My listBox is:
<ListBox Height="248" HorizontalAlignment="Left" Margin="141,223,0,0" Name="listBox" VerticalAlignment="Top" Width="378" />
原文:https://stackoverflow.com/questions/19680996
最满意答案
根据我的理解,实现这一目标的唯一方法是事先创建一个配置文件,并在nightwatch配置中使用该配置文件,类似于这里的文章: https : //github.com/nightwatchjs/nightwatch/wiki/Enable-Firebug-in-火狐换Nightwatch检验
我希望有一种方法来设置firefox首选项,因为我提供的解决方案依赖于在配置文件的机器上运行。
From my understanding the only way to accomplish this is to create a profile before hand and use that profile in nightwatch configuration, similar to the insructions here: https://github.com/nightwatchjs/nightwatch/wiki/Enable-Firebug-in-Firefox-for-Nightwatch-tests
I wish there was a way to set firefox preferences, since with the solution I'm providing your tests are dependent on running on the machine with the profile.
相关问答
更多-
好吧,现在它可以工作。 如果您遇到相同或类似的问题,请编辑harness-options.json文件。 后 "page-mod": { "path": "addon-kit/lib/page-mod.js" }, 加: "preferences-service": { "path": "api-utils/lib/preferences-service.js" }, /*with or without the comma, as the case may */ 就这样 :) Okay, now it ...
-
解决方案是为您的守夜测试创建一个Firefox配置文件。 1)创建一个新的Firefox配置文件: 在终端中,执行以下命令:“ firefox -p ” 然后创建一个名为“ webdriver ”的profil 。 2)配置新的配置文件 使用url: about:config转到此配置页面 搜索名称“ intl.accept_languages ”并更新值。 现在退出Firefox。 3)配置Nightwatch以使用新的配置文件 “webdriver.firefox.profile”:“ webdrive ...
-
在Firefox中使用首选项(Using preferences in Firefox)[2023-05-12]
看起来您需要在.xul文件中包含nsUserSettings.js : 这是定义nsUserPreferences位置。 有关示例options.xul文件,请参见此处 。 script标记应该是prefwindow的第一个子元素,以确保它在您自己的代码之前加载。 附加信息 这看起来像是一个关于如何编写Firefox扩展的体面 ... -
这是不可能的,而且可能永远不会。 来源:官方WebExtensions常见问题https://wiki.mozilla.org/WebExtensions/FAQ#Will_I_have_access_to_about:config_or_the_preferences.3F 另外,您可能对mozilla-community.org上的这个讨论感兴趣: https ://discourse.mozilla-community.org/t/webextension-read-write-access-to-a ...
-
您可以查看profile.DEFAULT_PREFERENCES ,它是python2.7/site-packages/selenium/webdriver/firefox/webdriver_prefs.json的json 。 {u'frozen': {u'app.update.auto': False, u'app.update.enabled': False, u'browser.EULA.3.accepted': True, u'browser.EULA.override': True, ...
-
取决于偏好的数量,有几个选项: 丢弃它们并让用户在升级后再次设置它们 使用与您的webextension通信的外部程序阅读它们,请参阅https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Native_messaging 制作一个导出到JSON(或类似的东西)的导出工具(外部程序)并在你的webextension中创建一个导入选项 除了上述选项之外,还有可能会有一个混合的webextension,它可以读取首选项并将其发布到addons.mozi ...
-
根据我的理解,实现这一目标的唯一方法是事先创建一个配置文件,并在nightwatch配置中使用该配置文件,类似于这里的文章: https : //github.com/nightwatchjs/nightwatch/wiki/Enable-Firebug-in-火狐换Nightwatch检验 我希望有一种方法来设置firefox首选项,因为我提供的解决方案依赖于在配置文件的机器上运行。 From my understanding the only way to accomplish this is to c ...
-
如何设置首选项?(How to set Preferences?)[2021-09-06]
此行无效: android:entryValues="@+array/listvalue" 您应该将其替换为: android:entryValues="@array/listvalue" 编辑: 数组资源有另一个名称: android:entryValues="@array/value" This line is not valid: android:entryValues="@+array/listvalue" You should replace it with: android:entryV ... -
使用Selenium在FireFox中设置首选项时出现mime类型问题(Issue with mime type when setting preferences in FireFox with Selenium)[2023-04-09]
以下是一组特定于CSV的mime类型,这些类型适用于SO上的其他用户: profile.setPreference('browser.helperApps.neverAsk.saveToDisk', "text/plain, application/vnd.ms-excel, text/csv, application/csv, text/comma-separated-values, application/download, application/octet-stream, binary/octet- ... -
这些首选项在较新的firefox版本中已更改。 转到about:config在firefox中about:config并搜索browser.download ,它会显示更新的内容。 例如, browser.download.dir现在是browser.download.lastDir These preferences have changed in newer firefox versions. Go to about:config in firefox and search for browser.do ...