0

enter image description here

I want to check one element, with help of that element id, prepared selenium web driver script, when will click on that ui element it will open another hided section on same window, but getting error "Element not visible" Before few days it was working with same script using "id" locator. I am learning automation and don't understand it was working before and now why getting this error. Please let me know if anyone faces this issue and have a solution to resolve it.

The HTML:

<h3 id="hubH3-524" title="pretest" ng-click="toggleSelection('hubH3-524','pretest',1)" role="button" tabindex="0" style="font-size: 9px; padding: 9px 0px 2px;">pretest</h3> 

My code:

   public class Simpletest {
 public static void main(String[] args) {
     try {
        System.setProperty("webdriver.chrome.driver","E:\\Selenium\\seleniumchromedriver\\chromedriver.exe");
        WebDriver driver= new ChromeDriver();
        driver.manage().deleteAllCookies();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.get("http://abc.com");
        driver.findElement(By.id("username")).sendKeys("enter email");
        driver.findElement(By.id("password")).sendKeys("enter password");
        driver.findElements(By.className("abcGenericButton")).get(2).click();
        Thread.sleep(1000); 
        new WebDriverWait(driver, 1000).until(ExpectedConditions.visibilityOf(driver.findElement(By.id("hubH3-3"))));
        //driver.findElement(By.id("hubH3-3")).click(); 
        driver.findElement(By.id("detailBtn")).click();
        driver.findElement(By.id("btnSettingsHub")).click();
        driver.findElement(By.id("hubDescription")).click();
        WebElement hubDescription = driver.findElement(By.id("hubDescription"));
        hubDescription.sendKeys("This is testing hub");
       } catch (Exception e) {
        e.printStackTrace();
 }        
 }
8
  • Can you please share code and html page ?
    – Sagar007
    Nov 7, 2017 at 9:42
  • More details would help us to encounter problem easily
    – Sagar007
    Nov 7, 2017 at 9:44
  • When user click on this element "Pretest", right side section "details" tab get display on same window. that pretest having id. so i used that id but getting error "no such element: Unable to locate element" driver.findElement(By.id("hubH3-3")).click(); Nov 7, 2017 at 10:14
  • Please share HTML code screenshot. Not HTML page.
    – Sagar007
    Nov 7, 2017 at 11:27
  • Its not working yet, getting error "no such element: Unable to locate element: {"method":"id","selector":"hubH3-3"}" Nov 7, 2017 at 11:44

1 Answer 1

1

As per your commented HTML code , This should be solution.

 Thread.sleep(1000); 
 new WebDriverWait(driver, 1000).until(ExpectedConditions.visibilityOf(By.xpath("//h3[contains(@id,'hubH3')]")));
 driver.findElement(By.xpath("//h3[contains(@id,'hubH3')]")).click();

Problem Statement :

  • Here id attribute is dynamic. So every time page gets load , it changing its count.

Solution :

  • So use contains or starts-with function in xpath. (Only xpath locator provides it.)

Note : I would suggest to wait for page load and then click.

3
  • Please comment here if any issues are there.
    – Sagar007
    Nov 7, 2017 at 12:28
  • I update bit things in code provided by you and its working. Thanks Sager Nov 8, 2017 at 5:39
  • @NilamNikam Please accept my answer as true if my answer able to solve issue.
    – Sagar007
    Nov 8, 2017 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.