• selenium常用获取元素点


    //通过id
    WebElement element = driver.findElement(By.id("coolestWidgetEvah"));
    //通过className List<WebElement> cheeses = driver.findElements(By.className("cheese"));
    //通过tagName WebElement frame = driver.findElement(By.tagName("iframe"));
    //通过name WebElement cheese = driver.findElement(By.name("cheese"));
    //通过linkText <a href="http://www.google.com/search?q=cheese">cheese</a> WebElement cheese = driver.findElement(By.linkText("cheese"));
    //通过部分linkText <a href="http://www.google.com/search?q=cheese">search for cheese</a> WebElement cheese = driver.findElement(By.partialLinkText("cheese"));
    //通过css <div id="food"><span class="dairy">milk</span><span class="dairy aged">cheese</span></div> WebElement cheese = driver.findElement(By.cssSelector("#food span.dairy.aged"));

    //通过xpath,比较麻烦


    //通过javaScript
    WebElement element = (WebElement) ((JavascriptExecutor)driver).executeScript("return $('.cheese')[0]");
    List<WebElement> labels = driver.findElements(By.tagName("label"));
    List<WebElement> inputs = (List<WebElement>) ((JavascriptExecutor)driver).executeScript(
        "var labels = arguments[0], inputs = []; for (var i=0; i < labels.length; i++){" +
        "inputs.push(document.getElementById(labels[i].getAttribute('for'))); } return inputs;", labels);
  • 相关阅读:
    2021广东省强网杯WriteUp
    2021 数字四川创新大赛WriteUp
    2021 陇剑杯wp
    2021 羊城杯WriteUP
    如何翻安全四大顶会的文章
    2021 祥云杯 wp
    codeql初探
    sqlmap应用
    sql注入2
    sql注入
  • 原文地址:https://www.cnblogs.com/jtestroad/p/7088583.html
Copyright © 2020-2023  润新知