【发布时间】:2019-05-24 15:10:53
【问题描述】:
我正在尝试使用 Selenium webdriver 定位图像,但无法通过 Xpath/cssSelector 定位它
我已经尝试过 cssSelector 和 xpath,但都不起作用。
<img alt="" class="i-amphtml-fill-content i-amphtml-replaced-content" decoding="async" src="https://tpc.googlesyndication.com/simgad/303052068860032968">
通过 cssSelector -->
WebElement elementOut = driver.findElement(By.cssSelector(".i-amphtml-fill-content.i-amphtml-replaced-content"));
通过 Xpath -->
WebElement elementOut = driver.findElement(By.xpath("//*[@id='aw0']/amp-img/img"));
我需要定位图像。
页面源截图:
【问题讨论】:
-
你能把你的图片所在页面的HTML代码贴出来吗?否则,将无法在这方面为您提供帮助。
-
HTML 代码:- tpc.googlesyndication.com/simgad/303052068860032968">
-
这只是
<img>标签。这不足以定位图像。您需要提供的是整个页面的 HTML 代码,或者至少是包含图像的所有 HTML 标记。另外,请将该代码添加到您的原始帖子中(您应该能够对其进行编辑,而不是在评论中)。这将使其更具可读性,人们将能够更轻松地为您提供帮助。 -
添加了详细页面来源的链接
-
您需要先选择
iframe!
标签: java selenium-webdriver xpath css-selectors webdriverwait