gpt4 book ai didi

java - 未使用 Selenium Web 驱动程序捕获数据

转载 作者:太空宇宙 更新时间:2023-11-04 12:31:17 25 4
gpt4 key购买 nike

我试图使用 ID 和标记名从网页捕获产品描述,但当我打印它时,它显示为空白。不过我认为我已经使用了正确的定位器来定位该元素。

页面来源

    <div id="item-description-block" class="layout-container layout-container-background clearfix">
<h2>About this item</h2>
<div id="social_share" class="details-row" onclick="javascript:clickPDP('Share','123070751499');">
<div class="details-row clear_both">
<div id="inspirational_copy">
<p>The big plus: Our new formula now helps strengthen skin's own moisture barrier. More moisture stays in. Skin feels soft, springy. Has a healthy-looking glow.</p>
</div>

网络驱动程序代码

driver.get("http://www.debenhams.com/webapp/wcs/stores/servlet/prod_10701_10001_123070751499_-1");
WebElement description =driver.findElement(By.id("inspirational_copy").tagName("p"));
String description1 = description.getText();

最佳答案

我刚刚在 Python 中对其进行了测试,如果您将 By.id("inspirational_copy").tagName("p") 替换为有效的 css 选择器,则可以使用 getText() 来获取您要查找的文本。

driver.get("http://www.debenhams.com/webapp/wcs/stores/servlet/prod_10701_10001_123070751499_-1");
WebElement description =driver.findElement(By.cssSelector("div[id='inspirational_copy']>p"));
String description1 = description.getText();

我确实注意到,当我到达该页面时,我收到了一条欢迎消息。该消息使我无法收到短信。关闭它后,我可以毫无问题地获取元素和文本。

WebElement close = driver.findElement(By.cssSelector("button[title='Close']");
close.click()

关于java - 未使用 Selenium Web 驱动程序捕获数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37832545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com