Warm tip: This article is reproduced from serverfault.com, please click

selenium-使用Java拦截的元素点击

(selenium - element click intercepted using Java)

发布于 2020-11-28 17:19:56

控制台显示以下错误:

Starting ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378}) on port 12848
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1606582973.595][WARNING]: This version of ChromeDriver has not been tested with Chrome version 87.
Nov 28, 2020 10:32:55 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit button"> is not clickable at point (522, 587). Other element would receive the click: <span class="desktop-text">...</span>
  (Session info: chrome=87.0.4280.66)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'PLANET', ip: '192.168.0.106', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '12.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 87.0.4280.66, chrome: {chromedriverVersion: 86.0.4240.22 (398b0743353ff..., userDataDir: C:\Users\Admin\AppData\Loca...}, goog:chromeOptions: {debuggerAddress: localhost:56606}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:virtualAuthenticators: true}
Session ID: 80bd603f6492d9dc7b4f71d2ae7d5edb
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at MailTest.main(MailTest.java:46)

我尝试使用等待和Javascript Executor,但是对于此错误没有任何运气。以下是我正在使用的代码:

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class MailTest {

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
        
        
        System.setProperty("webdriver.chrome.driver","C:/chromedriver.exe");
        
         WebDriver driver = new ChromeDriver();
        
        driver.get("testUrl");
         
        
        //Maximizing window
         driver.manage().window().maximize();
         
         driver.findElement(By.xpath("//body/div[@id='offer--modal']/div[1]/div[2]/p[1]")).click();
         Thread.sleep(10000);
         
         WebElement Name = driver.findElement(By.xpath("//input[@id='name']"));
         Name.sendKeys("test"); 
         
         WebElement email = driver.findElement(By.xpath("//input[@id='email']"));
         email.sendKeys("Gtest@gmail.com");
         
         
         WebElement Subject = driver.findElement(By.xpath("//input[@id='subject']"));
         Subject.sendKeys("Testing");
         
         driver.findElement(By.xpath("//span[contains(text(),'Mobile Development')]")).click();
         driver.findElement(By.xpath("//span[contains(text(),'Application Development')]")).click();
         
         driver.findElement(By.xpath("//textarea[@id='message']")).sendKeys("testing for automation");
    
        
     WebElement Sendbutton = driver.findElement(By.xpath("//body/div[4]/div[2]/div[1]/div[1]/div[1]/section[1]/div[1]/form[1]/div[7]/input[1]"));
         JavascriptExecutor executor = (JavascriptExecutor)driver;
         executor.executeScript("arguments[0].click()", Sendbutton);
         
         
        // driver.close();
         
    }

}

上面的脚本可以正常工作,直到我想单击“提交”按钮为止。另外,我觉得问题可能出在提交按钮的xpath上。我正在使用chropath查找xpath。

Questioner
Ghazal shukla
Viewed
0
SelectorsHub - The XPathTool 2021-01-05 03:40:30

你正在使用的XPath几乎是动态的,并且绝不建议将XPath与索引一起使用。必须具有一些属性,你可以使用该属性来编写“提交提交的xpath”按钮。

你的xpath可能像-

> //button[@class='submit']