简体   繁体   中英

Error as Element is not clickable at point in selenium

Dom structure :

 <li class="slds-dropdown-trigger slds-dropdown-trigger--click slds-m-left--
  x-small" data-aura-rendered-by="534:20;a">
 <!--render facet: 537:20;a-->
 <!--
 render facet: 541:20;a--><button class="bare slds-button uiButton 
 forceHeaderButton oneUserProfileCardTrigger" aria-live="off" type="button" 
 data-aura-rendered-by="184:190;a" data-aura-class="uiButton 
 forceHeaderButton 
 oneUserProfileCardTrigger"><!--render facet: 185:190;a--><!--render facet: 
 187:190;a-->
 <div class="tooltipTrigger tooltip-trigger uiTooltip" aria-describedby="tt-
 for-174:190;a" tabindex="-1" data-aura-rendered-by="179:190;a" data-aura-
 class="uiTooltip">
 <span data-aura-rendered-by="171:190;a" class="uiImage" 
 data-aura-class="uiImage"><img data-aura-rendered-by="169:190;a" 
 src="https://c.ap5.content.force.com/profilephoto/005/T/1" 
 class="profileTrigger" alt="">
 </span><span class="tooltip-invisible" 
 role="tooltip" id="tt-for-174:190;a" data-aura-rendered-by="181:190;a">View 
 profile</span>
 </div></button><!--render facet: 543:20;a-->
 </li>

i tried these lines of code for Logout :

First click on Logout symbol:

   WebDriverWait wait3 = new WebDriverWait(driver, 20); 
   driver.findElement(By.xpath("//img[@class = 'profileTrigger']")).click();
   JavascriptExecutor jse = (JavascriptExecutor)driver;
   /*exe1.executeScript("arguments[0].click();", newbt);*/
   jse.executeScript("scroll(250, 0)");

second click on Logout button :

 driver.findElement(By.xpath("//a[@class = 
       'profile-link-label logout uiOutputURL']"));

I am getting error as Element is not clickable at point.

1.Use scrollTo element by selector - this will ensure element is visible:

WebElement element = driver.findElement(By.xpath("//button[@class='oneUserProfileCardTrigger']"));
((JavascriptExecutor) driver)
    .executeScript("arguments[0].scrollIntoView(true);", element);

2.Always use delay or wait after scroll before click. It takes time for browser.

3.If nothing helps - use javascript click. Bad solution as it not like real user do, but will work always:

WebElement element = driver.findElement(By.xpath("//button[@class='oneUserProfileCardTrigger']"));
((JavascriptExecutor)driver)
    .executeScript("arguments[0].click();", element);

@SrieedherSanthakumar I have few that would like to clarify first, whether or not are you dependent on wait call. Like you are clicking on something and want to wait for something and then process with your second click ?

If so, you might have to modify your first call something like below :

 WebDriverWait wait3 = new WebDriverWait(driver, 20); 
       driver.findElement(By.xpath("//img[@class = 'profileTrigger']")).click();
    WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
       JavascriptExecutor jse = (JavascriptExecutor)driver;
       /*exe1.executeScript("arguments[0].click();", newbt);*/
       jse.executeScript("scroll(250, 0)");

once you have waited for your page to be load or expected id is visible then proceed with your second call. I am not able to see whether you are waiting for your object in the first call to load since you are clicking on profileTrigger before moving forward with your second call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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