2017-11-04 193 views
-1

A h:selectOneRadio結果<input type="radio">在表中和p:selectOneRadio<input type="radio">在表中有div s約input。這兩個ID都是[form id]:[selectOneRadio id]:[option number],我可以成功地用於石墨烯功能測試中的普通JSF,當訪問它時使用@FindBy(id="[...]"),而PrimeFaces變體由於org.openqa.selenium.ElementNotInteractableException而失敗。調查生成的HTML我看不出區別爲什麼我可以用type = radio的h:selectOneRadio單擊一個輸入,但不能用p:selectOneRadio與Graphene/Selenium之一進行輸入?

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <link type="text/css" rel="stylesheet" href="/34696ceb-eeaa-4b35-88dd-f3c8fc5901bf/javax.faces.resource/theme.css.xhtml?ln=primefaces-aristo"> 
    <link type="text/css" rel="stylesheet" href="/34696ceb-eeaa-4b35-88dd-f3c8fc5901bf/javax.faces.resource/primefaces.css.xhtml;jsessionid=48ca919d0b7e89661f92149ac321?ln=primefaces&amp;v=5.0"> 
    <script type="text/javascript" src="/34696ceb-eeaa-4b35-88dd-f3c8fc5901bf/javax.faces.resource/jquery/jquery.js.xhtml;jsessionid=48ca919d0b7e89661f92149ac321?ln=primefaces&amp;v=5.0"></script> 
    <script type="text/javascript" src="/34696ceb-eeaa-4b35-88dd-f3c8fc5901bf/javax.faces.resource/primefaces.js.xhtml;jsessionid=48ca919d0b7e89661f92149ac321?ln=primefaces&amp;v=5.0"></script> 
    <title>Facelet Title</title> 
</head> 

<body> 
    <form id="mainForm" name="mainForm" method="post" action="/34696ceb-eeaa-4b35-88dd-f3c8fc5901bf/index.xhtml;jsessionid=48ca919d0b7e89661f92149ac321" enctype="application/x-www-form-urlencoded"> 
    <input name="mainForm" value="mainForm" type="hidden"> 
    <table id="mainForm:mainSelectOneRadio"> 
     <tbody> 
     <tr> 
      <td> 
      <input name="mainForm:mainSelectOneRadio" id="mainForm:mainSelectOneRadio:0" value="a" type="radio"> 
      <label for="mainForm:mainSelectOneRadio:0"> a</label> 
      </td> 
      <td> 
      <input name="mainForm:mainSelectOneRadio" id="mainForm:mainSelectOneRadio:1" value="b" type="radio"> 
      <label for="mainForm:mainSelectOneRadio:1"> b</label> 
      </td> 
      <td> 
      <input name="mainForm:mainSelectOneRadio" id="mainForm:mainSelectOneRadio:2" value="c" type="radio"> 
      <label for="mainForm:mainSelectOneRadio:2"> c</label> 
      </td> 
     </tr> 
     </tbody> 
    </table> 
    <table id="mainForm:mainSelectOneRadioPrime" class="ui-selectoneradio ui-widget"> 
     <tbody> 
     <tr> 
      <td> 
      <div class="ui-radiobutton ui-widget"> 
       <div class="ui-helper-hidden-accessible"> 
       <input id="mainForm:mainSelectOneRadioPrime:0" name="mainForm:mainSelectOneRadioPrime" value="aPrime" type="radio"> 
       </div> 
       <div class="ui-radiobutton-box ui-widget ui-corner-all ui-state-default"><span class="ui-radiobutton-icon ui-icon ui-icon-blank"></span> 
       </div> 
      </div> 
      </td> 
      <td> 
      <label for="mainForm:mainSelectOneRadioPrime:0">aPrime</label> 
      </td> 
      <td> 
      <div class="ui-radiobutton ui-widget"> 
       <div class="ui-helper-hidden-accessible"> 
       <input id="mainForm:mainSelectOneRadioPrime:1" name="mainForm:mainSelectOneRadioPrime" value="bPrime" type="radio"> 
       </div> 
       <div class="ui-radiobutton-box ui-widget ui-corner-all ui-state-default"><span class="ui-radiobutton-icon ui-icon ui-icon-blank"></span> 
       </div> 
      </div> 
      </td> 
      <td> 
      <label for="mainForm:mainSelectOneRadioPrime:1">bPrime</label> 
      </td> 
      <td> 
      <div class="ui-radiobutton ui-widget"> 
       <div class="ui-helper-hidden-accessible"> 
       <input id="mainForm:mainSelectOneRadioPrime:2" name="mainForm:mainSelectOneRadioPrime" value="cPrime" type="radio"> 
       </div> 
       <div class="ui-radiobutton-box ui-widget ui-corner-all ui-state-default"><span class="ui-radiobutton-icon ui-icon ui-icon-blank"></span> 
       </div> 
      </div> 
      </td> 
      <td> 
      <label for="mainForm:mainSelectOneRadioPrime:2">cPrime</label> 
      </td> 
     </tr> 
     </tbody> 
    </table> 
    <input name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="-485558793831512050:990657069126697889" autocomplete="off" type="hidden"> 
    </form> 
</body> 

</html> 

況且我,如果我上部署似鯖水狼牙魚4.1.2或任何其他原因ElementNotInteractableException應用。

的獲取與

@RunWith(Arquillian.class) 
public class MyManagedBeanTest { 
    private static final String WEBAPP_SRC = "src/main/webapp"; 
    private final static Logger LOGGER = LoggerFactory.getLogger(MyManagedBeanTest.class); 

    @Deployment(testable = false) 
    public static Archive<?> createDeployment0() throws TransformerException, XPathExpressionException, ParserConfigurationException, SAXException, IOException { 
     WebArchive retValue = ShrinkWrap.create(WebArchive.class) 
       .add(EmptyAsset.INSTANCE, "beans.xml") 
       .addClasses(MyManagedBean.class) 
       .addAsWebInfResource(
         new StringAsset("<faces-config version=\"2.0\"/>"), 
         "faces-config.xml"); 
     Maven.configureResolver().workOffline().resolve("richtercloud:graphene-click-input-radio:war:1.0-SNAPSHOT").withoutTransitivity().asList(JavaArchive.class).forEach(dependency -> retValue.addAsLibrary(dependency)); 
     //add all webapp resources 
     retValue.merge(ShrinkWrap.create(GenericArchive.class) 
       .as(ExplodedImporter.class) 
       .importDirectory(WEBAPP_SRC) 
       .as(GenericArchive.class), "/", Filters.include(".*\\.(xhtml|css|js|png)$")); 

     ByteArrayOutputStream archiveContentOutputStream = new ByteArrayOutputStream(); 
     retValue.writeTo(archiveContentOutputStream, Formatters.VERBOSE); 
     LOGGER.info(archiveContentOutputStream.toString()); 
     return retValue; 
    } 

    @Drone 
    private WebDriver browser; 
    @ArquillianResource 
    private URL deploymentUrl; 
    @FindBy(id = "mainForm:mainSelectOneRadio:0") 
    private WebElement mainSelectOneRadioOption0; 
    @FindBy(id = "mainForm:mainSelectOneRadioPrime:0") 
    private WebElement mainSelectOneRadioPrimeOption0; 

    @Test 
    public void testAll() { 
     browser.get(deploymentUrl.toExternalForm()+"index.xhtml"); 
     LOGGER.debug(browser.getPageSource()); 
     mainSelectOneRadioOption0.click(); 
     mainSelectOneRadioPrimeOption0.click(); 
    } 
} 

的MCVE可以在https://github.com/krichter722/graphene-click-input-radio找到完成。

我正在使用PrimeFaces 6.1。

+1

確定您點擊了正確的元素?有了PF ypu需要點擊om與普通的jsf不同的東西,因爲原來的輸入被包裝了... – Kukeltje

+0

只有'div'和'input's參與,只有點擊'input'纔有意義。 –

回答

-2

我認爲你的定位器很好。如果我猜的話,這將是兩種情況之一:

  1. 你需要等待INPUT是點擊。在嘗試點擊它時,無法點擊。

    WebDriverWait wait = new WebDriverWait(driver, 15); 
    wait.until(ExpectedConditions.elementToBeClickable(...)); 
    
  2. 封裝了*總理ID的DIV

    <div class="ui-helper-hidden-accessible"> 
    

    我不知道這是否是相關的,因爲我看不到的頁面,但類名,我想知道元素是否最初沒有隱藏。是否需要在頁面上執行一些操作以顯示Prime INPUT?如果是這樣,代碼的行動,然後一旦INPUT被暴露它將是可點擊的。 Selenium設計爲與用戶交互頁面,因此它不會對不可見的元素執行操作(單擊,獲取文本等)。

相關問題