【问题标题】:Use selenium to click button and view more text使用 selenium 单击按钮并查看更多文本
【发布时间】:2019-09-30 14:15:26
【问题描述】:

从“https://us.burberry.com/womens-new-arrivals-new-in/”抓取数据。我需要向下滚动页面并单击“查看 126 更多”以获取更多文本。这是要点击的位置。

【问题讨论】:

    标签: python selenium-webdriver


    【解决方案1】:
    var element = driver.FindElement(By.Class("shelf-view-more-button-copy"));
    Actions actions = new Actions(driver);
    actions.MoveToElement(element);
    actions.Perform();
    

    【讨论】:

      【解决方案2】:

      当我检查 url 时,只有一个类具有价值:shelf-view-more-button-copy

      所以我认为您可以使用此代码:

      driver.findElement(By.xpath("//span[@class='shelf-view-more-button-copy']")).click();
      

      如果您还想滚动到它,可以在此之前添加此代码:

      WebElement element = driver.findElement(By.xpath("//span[@class='shelf-view-more-button-copy']"));
      
          ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();",element);
      

      【讨论】:

      • findElement - 来自 selenium import webdriver
      • webdriver.findElement(By.xpath("//span[@class'shelf-view-more-button-copy']")).click();回溯(最后一次调用):文件“”,第 1 行,在 webdriver.findElement(By.xpath("//span[@class'shelf-view-more-按钮复制']")).click(); AttributeError:模块“selenium.webdriver”没有属性“findElement”
      • 使用“find_element_by_xpath”。
      • 我正在使用 xpath - 不工作 browser.find_element_by_xpath('//*[@id="facet-result-render"]/div/div/div/div/div[2]/div /div/div[2]/a/div/div[1]').click();
      猜你喜欢
      • 1970-01-01
      • 2015-04-06
      • 2016-05-29
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      相关资源
      最近更新 更多