简体   繁体   English

具有Selenium Webdriver的Primefaces selectOneMenu无法选择项目+ Java

[英]Primefaces selectOneMenu with Selenium webdriver does not select the item + Java

I need to set value on p:selectOneMenu during my selenium test but having problem to set the value. 我需要在硒测试期间在p:selectOneMenu上设置值,但是在设置值时遇到问题。 here is the code i used to do that: 这是我用来做的代码:

{
driver.findElement(By.id("myForm:meSelection_label")).click();
driver.findElement(By.xpath("//div[@id='myForm:meSelection_panel']/div[2]/ul/li[text() = 'mytext']")).click();
}

Problem is that it does not select my selection, i even tried to use index on li (eg /li[2]) it is second item. 问题是它没有选择我的选择,我什至试图在li上使用索引(例如/ li [2]),这是第二项。 when i run the test it shows the dropdown list and i can see my elements in it but it just do not select the element. 当我运行测试时,它会显示一个下拉列表,并且我可以看到其中的元素,但只是不选择该元素。 And yes, i do have converter on for this object. 是的,我确实为此对象安装了转换器。 I also tried Selenium IDE and put my xpath in there exactly the same as above and it works perfectly fine, but in my test case in java it does not select the element at all. 我还尝试了Selenium IDE,并将我的xpath放在与上面完全相同的位置,并且工作得很好,但是在我的Java测试案例中,它根本没有选择该元素。

I searched the net and forums but could not find any solutions for it. 我搜索了网络和论坛,但找不到任何解决方案。 It seams some people had problems with it but no answers were posted on these questions. 它缝制了一些人对此有问题的方法,但是这些问题没有答案。

here is my pom.xml with dependencies for testing: 这是我的带有测试依赖项的pom.xml:

{

<dependency>
        <groupId>org.seleniumhq.selenium.client-drivers</groupId>
        <artifactId>selenium-java-client-driver</artifactId>
        <version>1.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.40.0</version>
    </dependency> 
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.40.0</version>
    </dependency> 
}

Any help would be much appreciated. 任何帮助将非常感激。

For select lists you need to create the selenium select object. 对于选择列表,您需要创建硒选择对象。

WebElement we = find         element(by.cssSelector("whatever the select is"))
Select s = new Select(we);
s.selectByValue("value to select")

Pseudo code I didn't test it 伪代码我没有测试

It is working now. 现在正在工作。 I did not do any changes to my code. 我没有对代码进行任何更改。 but i suspecting that me switching between different repositories and not rebuilding them fully caused problem when i tried to run my tests. 但是我怀疑我尝试在不同的存储库之间切换而不完全重建它们时,会导致问题。 So thank to everyone who looked and tried to help. 因此,感谢所有寻求帮助的人。

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

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