Selenium等待可点击元素点击拦截问题



我在硒中等待时遇到问题。我想按下一个元素,并得到关于拦截的错误。我尝试了所有的解决方案,比如元素是等待元素,可以点击等等,但什么都没用。

如何解决此异常,并告诉selenium等待此元素被删除/不可见/消失?

Sun Oct 27 14:03:53 IST 2019:INFO: WebDriver: Click on [[ChromeDriver: chrome on XP (bf4a41cbd3e7f6cfedb2f70301ed0512)] -> id: header-account]
Sun Oct 27 14:03:53 IST 2019:ERROR: element click intercepted: Element <button _ngcontent-egd-c11="" class="avatar-style ant-btn ant-btn-default ant-btn-circle" id="header-account" nz-button="" nz-popover="" nzplacement="bottomRight" nzshape="circle" nztrigger="click" ng-reflect-nz-shape="circle" ng-reflect-nz-content="[object Object]" ng-reflect-nz-trigger="click" ng-reflect-nz-placement="bottomRight" ng-reflect-directive-name-title="" nz-wave="[object Object]">...</button> is not clickable at point (1888, 31). Other element would receive the click: <path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path>
(Session info: chrome=78.0.3904.70)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PC', ip: '10.3.3', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_65'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.70, chrome: {chromedriverVersion: 77.0.3865.40 (f484704e052e0..., userDataDir: C:UsersSagiAppDataLocal...}, goog:chromeOptions: {debuggerAddress: localhost:56066}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: bf4a41cbd3e7f6cfedb2f70301ed0512

我只想让硒元素等待它可以点击,然后我就可以按下元素了。我该如何克服它?因为没有得到点击的元素的Id,而不是Class just:

Other element would receive the click: <path d="M563.8 512l262.5-312.9c4.4-5.2.7-13.1-6.1-13.1h-79.8c-4.7 0-9.2 2.1-12.3 5.7L511.6 449.8 295.1 191.7c-3-3.6-7.5-5.7-12.3-5.7H203c-6.8 0-10.5 7.9-6.1 13.1L459.4 512 196.9 824.9A7.95 7.95 0 0 0 203 838h79.8c4.7 0 9.2-2.1 12.3-5.7l216.5-258.1 216.5 258.1c3 3.6 7.5 5.7 12.3 5.7h79.8c6.8 0 10.5-7.9 6.1-13.1L563.8 512z"></path>

这是可以改变的(会话信息:chrome=78.0.3904.70(

您可以将chrome缩小到75%我用这个解决了我的问题,但这不是一个完美的解决方案所以你可以使用

ActionChains(driver).move_by_offset(#coordinates).click().perform()

然后要恢复到原来的位置,请使用

ActionChains(driver).move_by_offset(-coordinates).click().perform()
请更新您的代码。

尝试使用Actions类:

WebElement element = driver.findElement(By.id("header-account"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
  1. 元素未被单击,因为它不在Viewport中

尝试使用JavascriptExecutor将元素带入Viewport:

WebElement myelement = driver.findElement(By.id("header-account"));
JavascriptExecutor jse2 = (JavascriptExecutor)driver;
jse2.executeScript("arguments[0].scrollIntoView()", myelement); 

相关内容

  • 没有找到相关文章

最新更新