XPath 找不到元素
我想从此页面抓取链接。 https://www.youtube.com/results?search_query=food+recepies
WebElement w1 = driver.findElement(By.xpath("//a[@id=\"video-title\"]"));
WebElement w2 = driver.findElement(By.xpath("//*a[@id='video-title']"));
WebElement w3 = driver.findElement(By.xpath("//a[@class='yt-simple-endpoint style-scope ytd-video-renderer']"));
WebElement w4 = driver.findElement(By.xpath("//h3/a"));
String link = w1.getAttribute("href");
这些都不适合我。
Error: Unable to locate element: //a[@id="video-title"]
I want to scrape links from this page.
https://www.youtube.com/results?search_query=food+recepies
WebElement w1 = driver.findElement(By.xpath("//a[@id=\"video-title\"]"));
WebElement w2 = driver.findElement(By.xpath("//*a[@id='video-title']"));
WebElement w3 = driver.findElement(By.xpath("//a[@class='yt-simple-endpoint style-scope ytd-video-renderer']"));
WebElement w4 = driver.findElement(By.xpath("//h3/a"));
String link = w1.getAttribute("href");
None of these works for me.
Error: Unable to locate element: //a[@id="video-title"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该适用于标题。
然而,其中有27个。因此,您可能想要使用
另一件事,您可能想要等到元素在页面上可见、启用、可单击等。为此,您需要执行以下操作:
This should work for the title.
However, there are 27 of them. So, you might want to use
Another thing is that you might want to wait until the elements are visible, enabled, clickable, etc., on the page. For this, you need to do something like the following: