Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while checking the clickable web element

I am facing problem while checking the clickable web element. So i have to check the alphabetic series and some of the alphabet are clickable and some are not clickable.

i used for loop for it starting with xpath of alphabet 'A' and going in loop till alphabet 'Z'.

but as soon as xpath of alphabet A is click & pass it goes to alphabet 'B' which is not clickable and due to this whole script is getting fail.

here is the code

for(int j=3; j<=26;j++) {
    String T1 =".//*[@id='twctvEl']/div/div/div[1]/ul/li[";
    String T2 = "]/a";
    String T12 = T1+j+T2;
    chrome.findElement(By.xpath(T12)).click();
    String alpha =chrome.findElement(By.xpath(T12)).getText();
    System.out.println("checking the alphabet"+alpha);
}

Please advice here

NOTE: In the series of alpha bet from A-Z only B,Q,S,X,Y,Z are not clickable rest all are clickable.

like image 890
ankit rawat Avatar asked Jul 09 '26 10:07

ankit rawat


1 Answers

You can add waits before element to become clickable:

for(int j=3; j<=26;j++) 

{

    String T1 =".//*[@id='twctvEl']/div/div/div[1]/ul/li[";
    String T2 = "]/a";        
    String T12 = T1+j+T2;        
    WebElement el = chrome.findElement(By.xpath(T12));        
    WebDriverWait wait = new WebDriverWait(driver, timeout);            
    WebElement el= wait.until(ExpectedConditions.elementToBeClickable(element));
    el.click();        
    String alpha =el.getText();       
    System.out.println("checking the alphabet"+alpha);

}
like image 166
Sanja Paskova Avatar answered Jul 12 '26 00:07

Sanja Paskova



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!