尝试全部..执行单击但单击并获取错误后不显示div。

时间:2018-04-21 08:51:06

标签: java html selenium

我正在尝试单击按钮,但获取错误元素在点(1333,75)处无法点击。其他元素将收到点击。我使用谷歌浏览器版本65。



<li class="slds-dropdown-trigger slds-dropdown-trigger--click slds-m-left--x-small" data-aura-rendered-by="484:0">
<!--render facet: 489:0--><!--render facet: 490:0-->
<button class="bare branding-userProfile-button slds-button uiButton forceHeaderButton oneUserProfileCardTrigger" aria-live="off" type="button" data-aura-rendered-by="159:184;a" data-aura-class="uiButton forceHeaderButton oneUserProfileCardTrigger">
<!--render facet: 160:184;a-->
<!--render facet: 162:184;a-->
<div class="tooltipTrigger tooltip-trigger uiTooltip" aria-describedby="tt-for-149:184;a" tabindex="-1" data-aura-rendered-by="154:184;a" data-aura-class="uiTooltip" id="154:184;a">
<span class="photoContainer forceSocialPhoto" data-aura-rendered-by="1312:0" data-aura-class="forceSocialPhoto" style="">
<span data-aura-rendered-by="1376:0" class="uiImage" data-aura
class="uiImage">
<img data-aura-rendered-by="1374:0"
src="https://ap5.salesforce.com/_slds/images/themes/lightning_blue/lightning_blue_profile_avatar_96.png" class="profileTrigger branding-user-profile circular" alt="User" title="User">
</span>
</span>
<!--render facet: 146:184;a-->
<span class="tooltip-invisible" role="tooltip" id="tt-for-149:184;a" 
data-aura-rendered-by="156:184;a">View profile
</span>
</div>
</button>
</li>
&#13;
&#13;
&#13;

同样点击按钮需要加速。 按钮X路径是html / body / div [5] / div [1] / header / div [3] / span / ul / li [9] / button

&#13;
&#13;
<div class="container" style="border:thick;color:red" data-aura-rendered-by="116:1956;a">
<!--render facet: 117:2575;a-->
</div>
&#13;
&#13;
&#13;

我使用以下代码执行单击以解决错误,但仍显示错误

driver= new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
WebElement element=driver.findElement('locator'));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
JavascriptExecutor js =(JavascriptExecutor)driver;
js.executeScript("window.scrollTo(0,"+element.getLocation().y+")");
element.click();

1 个答案:

答案 0 :(得分:0)

使用以下代码段代替动作类的moveToElement

WebElement element = driver.findElement(locator);
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

点击使用JavaScriptExecutor:

WebElement element = driver.findElement(locator);
    ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);