我尝试了以下代码:
driver.findElement(By.xpath("//img[@src='https://c.ap5.content.force.com/profilephoto/005/T/1']")).click();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].click();", newbt);
//clicking Log out button.
driver.findElement(By.xpath("//a[contains(@class, 'profile-link-label logoutuiOutputURL')]")).click();
我收到以下错误:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not
clickable at point (1231, 25). Other element would receive the click: <div
class="panel slds-modal slds-fade-in-open" aria-labelledby="title_2099:0"
tabindex="-1" role="dialog" data-aura-rendered-by="2115:0" style="opacity:
1;">...</div>
注销的Dom结构:
<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>
有人可以解释为什么这不起作用并可能建议修复?谢谢。
答案 0 :(得分:0)
这里发生的事情是注销按钮前面还有另一个元素。如果没有看到正在测试的实际页面,有一些可能是错误的,但这里有一些潜在的解决方案。
答案 1 :(得分:0)
尝试使用javascript executor
单击WebElement e = driver.findElement(By.xpath("//a[contains(@class, 'profile-link-label logout uiOutputURL')]"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", e);
希望它能帮到你
答案 2 :(得分:0)
点击用户名,以便注销按钮变为可见。
driver.findElement(by.xpath("//div[@id='userNavButton']/span")).click();
现在点击退出按钮。
driver.findElement(by.xpath("//a[contains(text(),'Logout')]")).click();
希望这会对你有所帮助。感谢。