我想在 Google 主页上搜索 Prime Video,然后我想在 Google 搜索页面上点击新闻链接。我已经使用 xpath 找到了这个链接,但是在执行代码时,我得到了 NoSuchElementException。我使用了下面的代码,请帮助我知道为什么下面的代码不起作用::
System.setProperty("webdriver.gecko.driver", "C:/Users/gecko/geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com/");
WebElement ele = driver.findElement(By.name("q"));
ele.sendKeys("prime video");
ele.submit();
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement news = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='hdtb-msb-vis']//div[text()='News']")));
news.click();
driver.close();
倚天杖
跃然一笑
富国沪深
随时随地看视频慕课网APP
相关分类