2016-09-15 7 views
1

일식 네온, 셀레늄 webdriver 2.53.0 및 firefox 45.3.0 esr에서 작업 중입니다. 셀레늄을 사이트의 유일한 체크 박스로 표시 할 수 없습니다. 여기 내 테스트 스크립트입니다셀레늄 webdriver가 체크 박스를 클릭 할 수 없습니다.

package testy; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.By; 
import org.openqa.selenium.Keys; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.Select; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.Test; 

public class rejestr { 
    public WebDriver driver; 
    @BeforeMethod 
    public void beforeMethod() { 
     driver = new FirefoxDriver(); 
     driver.manage().window().maximize(); 
     driver.navigate().to("http://dev.wedkarz.pzw.pl/#/login"); 
    } 
    @Test 
    public void f() throws InterruptedException { 
     driver.findElement(By.className("nav-item")).click(); 
     driver.findElement(By.id("firstName")).sendKeys("Jan"); 
     driver.findElement(By.id("lastName")).sendKeys("Nowak"); 
     driver.findElement(By.id("email")).sendKeys("[email protected]"); 
     driver.findElement(By.id("plainPassword")).sendKeys("password"); 
     new Select(driver.findElement(By.id("district"))).selectByVisibleText("Okręg  PZW w Bydgoszczy"); 
     new Select(driver.findElement(By.id("circle"))).selectByVisibleText("Koło PZW nr 31"); 
     driver.findElement(By.id("fishingLicense")).sendKeys("12345678990"); 
     driver.findElement(By.id("squaredOne")).click(); 
    } 
    @AfterMethod 
    public void afterMethod() { 
     System.out.print("Test zakończony powodzeniem"); 
     driver.quit(); 
    } 
} 

그리고 그 체크 박스에 대한 HTML 코드입니다 : 내가 2 일 동안 함께 싸우고했기 때문에

<div class="row form-group m-b-lg"> 
       <div class="squaredOne"> 
       <input id="squaredOne" name="check" type="checkbox" value="None" class="ng-untouched ng-valid ng-dirty"> 
       <label for="squaredOne"> 
        <p>Wyrażam zgodę na otrzymywanie od PZW informacji<br> o charakterze promocyjnym i reklamowym 
        przekazywanych drogą elektroniczną, w tym przesyłanych z wykorzystaniem telekomunikacyjnych 
        urządzeń końcowych (np. komputer, tablet).</p> 
       </label> 
       </div> 
       <span class="help-block"> 

       </span> 
      </div> 

는 당신의 도움을 주셔서 감사합니다 정말겠습니까.

+0

어떤 브라우저를 사용하고 있습니까? – Techidiot

+0

내가 언급 한대로 - firefox 45.3.0 esr –

답변

1

당신이 조금 까다로운 IE 브라우저에있는 경우 -

if (driver.Capabilities.BrowserName.Equals(“internet explorer")) 
    driver.findElement(By.id("squaredOne").SendKeys(Keys.Space); 
else 
    driver.findElement(By.id("squaredOne").Click(); 

또는 문제가 해결되지 않으면 요소를

driver.findElement(By.xpath("//input[@type='checkbox']")).click(); 

에 도달하기 위해 XPath는을 사용하여 시도, 클래스 이름

를 사용해보십시오
WebElement mybox = driver.findElement(By.className("squaredOne"));  
mybox.click(); 
+0

마지막 스크립트가 제대로 작동합니다. 정말 고맙습니다. –

+0

@JRodDynamite - 뭔가를 놓친다는 느낌이 들면 답을 편집하십시오. 그리고 OP는 나중에 추측했다. – Techidiot

+0

@Techidiot - 내 투표를 취소했습니다. 서둘러 질문을 읽으십시오. 내 잘못이야. – JRodDynamite

0

코드 driver.findElement(By.id("squaredOne")).click()이 작동해야합니다. 그렇지 않은 경우에, 당신은 시도 할 수 있습니다 :

  1. 변경 선택기를 XPath는에 :

    driver.findElement(By.xpath("//input[@id='squaredOne']")).click(); 
    
  2. 클릭 부모 DIV :

    driver.findElement(By.xpath("//div[./input[@id='squaredOne']]")).click()` 
    
  3. 를 사용하여 작업 클래스 :

    Actions actions = new Actions(driver); 
    actions.click(driver.findElement(By.xpath("//input[@id='squaredOne']"))); 
    actions.build().perform(); 
    
관련 문제