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和java中使用if语句时进行检查_Java_Selenium_Selenium Webdriver - Fatal编程技术网

正在获取警报插入'=空';在selenium和java中使用if语句时进行检查

正在获取警报插入'=空';在selenium和java中使用if语句时进行检查,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,代码如下所示: public class Click { private WebDriver driver; @Test public void Tocheckdifferentclickfeatures() throws InterruptedException { System.setProperty("webdriver.chrome.driver", "C:\\Users\\abhishek.gautam\\workspace\\chromedriv

代码如下所示:

public class Click {
private WebDriver driver;

@Test
public void Tocheckdifferentclickfeatures()  throws InterruptedException {

    System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\abhishek.gautam\\workspace\\chromedriver.exe");

    WebDriver driver = new ChromeDriver();

    driver.get("https://in.bookmyshow.com/mumbai");

    driver.manage().window().maximize();

    Thread.sleep(3000);
    driver.findElement(By.id("wzrk-cancel")).click();
    Thread.sleep(3000);
    driver.findElement(By.xpath("//*[@id='navbar']/div[2]/div/ul[1]/li[3]/a")).click();
    driver.findElement(By.xpath("//*[@id='navbar']/div[2]/div/ul[1]/li[3]/a")).click();
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("window.scrollBy(0,250)", "");
    Thread.sleep(3000);
    if(driver.findElement(By.linkText("Sunburn Arena with Martin Garrix (Mumbai)"))).isDisplayed()
我在这一行中得到了错误:


按如下方式修改代码:

if(driver.findElement(By.linkText("Sunburn Arena with Martin Garrix (Mumbai)")).isDisplayed()){
   //your code goes here
}

单击图像链接“Getting the alert Insert'!=null'check”了解更多详细信息在if()中添加isDisplayed()实际上错误是“类型不匹配:无法将WebElement转换为布尔值”;建议的修复方法是“插入=空'。您有一个额外的关闭参数,它在
.isDisplayed()
之前终止if表达式。删除额外的关闭参数,这样你就有了一个有效的表达式。嘿,它起作用了,但是你能解释一下你在这里到底做了什么,代码起作用了吗?@AbhishekGautam这是你的语法错误。您将isDisplayed()方法置于if条件之外。