Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
selenium webdriver giving;未知错误:元素在点(747238)处不可单击;单击日期选择器时_Selenium_Selenium Webdriver - Fatal编程技术网

selenium webdriver giving;未知错误:元素在点(747238)处不可单击;单击日期选择器时

selenium webdriver giving;未知错误:元素在点(747238)处不可单击;单击日期选择器时,selenium,selenium-webdriver,Selenium,Selenium Webdriver,我得到以下错误: package redbus; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.interactions.Actions; public class Searchforbus { public static vo

我得到以下错误:

package redbus;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class Searchforbus {

   public static  void main(String[] args) throws InterruptedException  {
     System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
     ChromeDriver driver = new ChromeDriver();
     driver.get("http://www.redbus.in/");
     driver.manage().window().maximize();
     driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
     driver.findElementById("src").sendKeys("Nagercoil");
     driver.findElementByClassName("selected").click();
     driver.findElementById("dest").sendKeys("Chennai");
     driver.findElementByClassName("selected").click();
     Thread.sleep(3000);
     driver.findElementById("onward_cal").click();
     WebElement element1= driver.findElementByXPath("//div[@id='rb-calendar_onward_cal']/table/tbody/tr[3]/td[6]");
     System.out.println("Check1");
     Actions builder= new Actions(driver);
     builder.moveToElement(element1).click().perform();
     System.out.println("Check2");


    }

}
线程“main”org.openqa.selenium.WebDriverException中的异常:未知错误:元素在点(747238)处不可单击。其他元素将收到单击:。。。
(会话信息:chrome=54.0.2840.99)
位于redbus.Searchforbus.main(Searchforbus.java:28)

@vinu定位器元素1中提供的日期指向12月3日,该日期在日历中被禁用,因为它已过日期,请确保提供启用/可用日期

在单击日历等棘手的元素之前,养成使用显式等待条件的习惯 e、 g WebDriverWait wait=新的WebDriverWait(驱动程序,15)

wait.until(ExpectedConditions.elementtobelickable(By.xpath(“element_xpath”))


拉胡尔是对的。您选择了已禁用的过去日期。尝试选择未来日期,如果失败,请告诉我们错误是什么。

import java.awt.Robot;
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (747, 238). Other element would receive the click: <label for="onward_cal" style="font-family:Lato" class="db text-trans-uc move-up">...</label>
  (Session info: chrome=54.0.2840.99)

at redbus.Searchforbus.main(Searchforbus.java:28)
导入java.awt.event.KeyEvent; 导入java.io.File; 导入java.util.List; 导入java.util.NoSuchElementException; 导入java.util.Set; 导入org.apache.commons.io.FileUtils; 导入org.openqa.selenium.By; 导入org.openqa.selenium.JavascriptExecutor; 导入org.openqa.selenium.NoAlertPresentException; 导入org.openqa.selenium.OutputType; 导入org.openqa.selenium.StaleElementReferenceException; 导入org.openqa.selenium.TakesScreenshot; 导入org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebDriverException; 导入org.openqa.selenium.WebElement; 导入org.openqa.selenium.support.ui.ExpectedConditions; 导入org.openqa.selenium.support.ui.WebDriverWait; 公共类CommonEleniumits扩展驱动程序{ 静态WebDriver=driver.getDriver(); public void switchToWindowByTitle(字符串标题){ 设置windows=driver.getWindowHandles(); System.out.println(“当前存在的窗口数量::”+windows.size()); 用于(字符串窗口:windows){ 驱动程序.切换到().窗口(窗口); if(driver.getTitle().startsWith(title)| | driver.getTitle().equalsIgnoreCase(title)){ 打破 }否则{ 继续; } } } public void clickWithJS(WebElement elementtoclick){ WebDriverWait wait=newwebdriverwait(driver,Long.parseLong(ConfigurationReader.getProperty(“超时”)); 等待.until(ExpectedConditions.elementtobelickable(elementtoclick)); ((JavascriptExecutor)driver.executeScript(“参数[0]。ScrollingToView(true);”,elementtoclick); ((JavascriptExecutor)driver).executeScript(“参数[0]。单击();”,elementtoclick); } 公共void waitforPresence元素(字符串css){ WebDriverWait wait=newwebdriverwait(driver,Long.parseLong(ConfigurationReader.getProperty(“超时”)); wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(css)); } public void waitforvisibilityofelement(WebElement元素){ WebDriverWait wait=newwebdriverwait(driver,Long.parseLong(ConfigurationReader.getProperty(“超时”)); 等待直到(元素的预期条件可见度); } 公共void waitForStaleElement(WebElement元素){ int i=0; 而(i<10){ 试一试{ 元素。isDisplayed(); 打破 }捕获(StaleElementReferenceException e){ 试一试{ 睡眠(500); }捕捉(中断异常e1){ e1.printStackTrace(); } e、 printStackTrace(); i++; }捕获(无接触元素例外e){ 试一试{ 睡眠(500); }捕捉(中断异常e1){ e1.printStackTrace(); } e、 printStackTrace(); i++; }catch(webdrivexception){ 试一试{ 睡眠(500); }捕捉(中断异常e1){ e1.printStackTrace(); } e、 printStackTrace(); i++; } } } 公共布尔值verifyElementIsNotPresent(字符串xpath){ List elemetns=driver.findElements(By.xpath(xpath)); 返回elemetns.size()==0; } 公共布尔值验证元素不存在(由){ List elemetns=driver.findElements(按); 返回elemetns.size()==0; } public void scrollToElement(WebElement元素){ ((JavascriptExecutor)driver.executeScript(“参数[0]。ScrollingToView(true);”,元素); } public void hitEnterUsingRobot(){ 机器人rb; 试一试{ rb=新机器人(); rb.keyPress(KeyEvent.VK_ENTER); rb.keyRelease(KeyEvent.VK_输入); }捕获(例外e){ System.out.println(e.getMessage()); } } 公共布尔值verifyAlertPresent(){ 试一试{ driver.switchTo().alert(); 返回true; }捕获(NoAlertPresentException Ex){ System.out.println(“警报不是presenet”); } 返回false; } 公共静态无效快照(){ 试一试{ TakesScreenshot scrShot=((TakesScreenshot)驱动程序); 文件SrcFile=scrShot.getScreenshotAs(OutputType.File); 字符串路径=System.getProperty(“user.dir”)+“\\screenshots.jpg”; System.out.println(路径); 文件DestFile=新文件(路径); copyFile(SrcFile,DestFile); }捕获(例外e){ System.out.println(e.getMessage()); } } public void safeJavaScriptClick(WebElement元素)引发异常{ 试一试{ if(element.isEnabled()&&el
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;


import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class CommonSeleniumUtils extends Driver {

     static WebDriver driver = Driver.getDriver();

    public void switchToWindowByTitle(String title) {
        Set<String> windows = driver.getWindowHandles();
        System.out.println("Amount of windows that are currently present :: " + windows.size());
        for (String window : windows) {
            driver.switchTo().window(window);
            if (driver.getTitle().startsWith(title) || driver.getTitle().equalsIgnoreCase(title)) {
                break;
            } else {
                continue;
            }
        }
    }

    public void clickWithJS(WebElement elementtoclick) {
        WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
        wait.until(ExpectedConditions.elementToBeClickable(elementtoclick));
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", elementtoclick);
        ((JavascriptExecutor) driver).executeScript("arguments[0].click();", elementtoclick);
    }

    public void waitForPresenceOfElementByCss(String css) {
        WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
        wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(css)));
    }

    public void waitForVissibilityOfElement(WebElement element) {
        WebDriverWait wait = new WebDriverWait(driver, Long.parseLong(ConfigurationReader.getProperty("timeout")));
        wait.until(ExpectedConditions.visibilityOf(element));
    }

    public void waitForStaleElement(WebElement element) {
        int i = 0;
        while (i < 10) {
            try {
                element.isDisplayed();
                break;
            } catch (StaleElementReferenceException e) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                e.printStackTrace();
                i++;
            } catch (NoSuchElementException e) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                e.printStackTrace();
                i++;
            } catch (WebDriverException e) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                e.printStackTrace();
                i++;
            }
        }
    }

    public boolean verifyElementIsNotPresent(String xpath) {
        List<WebElement> elemetns = driver.findElements(By.xpath(xpath));
        return elemetns.size() == 0;
    }

    public boolean verifyElementIsNotPresent(By by) {
        List<WebElement> elemetns = driver.findElements(by);
        return elemetns.size() == 0;
    }

    public void scrollToElement(WebElement element) {
        ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
    }

    public void hitEnterUsingRobot() {
        Robot rb;
        try {
            rb = new Robot();
            rb.keyPress(KeyEvent.VK_ENTER);
            rb.keyRelease(KeyEvent.VK_ENTER);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    public boolean verifyAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException Ex) {
            System.out.println("Alert is not presenet");
        }
        return false;
    }

    public static void takeSnapShot() {
        try {
            TakesScreenshot scrShot = ((TakesScreenshot) driver);
            File SrcFile = scrShot.getScreenshotAs(OutputType.FILE);
            String path = System.getProperty("user.dir") + "\\screenshots.jpg";
            System.out.println(path);
            File DestFile = new File(path);
            FileUtils.copyFile(SrcFile, DestFile);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
    public void safeJavaScriptClick(WebElement element) throws Exception {
        try {
            if (element.isEnabled() && element.isDisplayed()) {
                System.out.println("Clicking on element with using java script click");

                ((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
            } else {
                System.out.println("Unable to click on element");
            }
        } catch (StaleElementReferenceException e) {
            System.out.println("Element is not attached to the page document "+ e.getStackTrace());
        } catch (NoSuchElementException e) {
            System.out.println("Element was not found in DOM "+ e.getStackTrace());
        } catch (Exception e) {
            System.out.println("Unable to click on element "+ e.getStackTrace());
        }
    }
}

After this, call this method ===>>> safeJavaScriptClick


     WebElement element =  driver.findElement(By.xpath("YOUR XPATH"));
        try {
            seleniumTools.safeJavaScriptClick(element);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }