GVKun编程网logo

Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?(selenium获取js加载后的页面)

215

本文的目的是介绍JavaSelenium:如何在不首先加载页面的情况下获取网页的HTML?的详细情况,特别关注selenium获取js加载后的页面的相关信息。我们将通过专业的研究、有关数据的分析等多种

本文的目的是介绍Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?的详细情况,特别关注selenium获取js加载后的页面的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?的机会,同时也不会遗漏关于c# – 如何在不重新加载页面的情况下刷新下拉列表?、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、GitHub如何在不重新加载页面的情况下更改URL?、javascript – 如何在不重新加载页面的情况下更改地址栏中的URL?的知识。

本文目录一览:

Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?(selenium获取js加载后的页面)

Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?(selenium获取js加载后的页面)

使用Selenium WebDriver for Java,是否可以在给定URL的情况下获取网页的HTML?

我知道,一旦在浏览器中加载了网页,就可以使用WebDriver.getPageSource()获得HTML。但是,为了提高效率,是否可以在不先将页面加载到浏览器中的情况下获取HTML?

c# – 如何在不重新加载页面的情况下刷新下拉列表?

c# – 如何在不重新加载页面的情况下刷新下拉列表?

我的页面中有两个下拉列表:
<asp:DropDownList AutopostBack="True" OnSelectedindexChanged="ddlMain_SelectedindexChanged" ClientIDMode="Static" ID="ddlMain" name="searchPhys"runat="server" AppendDataBoundItems="true">
    <asp:ListItem Text="BY PHYSICIAN" Value="0" Selected="True" />
    <asp:ListItem Text="BY LOCATION" Value="1" />
    <asp:ListItem Text="BY SPECIALTY" Value="2" />
</asp:DropDownList>

<br /><br />

<asp:DropDownList ClientIDMode="Static" ID="ddlDrillDown" name="searchPhys"runat="server" AppendDataBoundItems="true">
</asp:DropDownList>

我处理下拉列表更改的代码隐藏是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.sqlClient;
using System.Xml.Linq;
using System.Configuration;
using System.Windows.Forms;
using System.Data;

public partial class physicians : System.Web.UI.Page
{

    protected void Page_Load(object sender,EventArgs e) {

    if (!Page.IsPostBack) {
        PopulatePhysician();
    }
    //PopulateSpecialty();
    //PopulateLocation();

    }

    public void PopulatePhysician() {
        sqlCommand cmd = new sqlCommand("getPhysicians",new sqlConnection(ConfigurationManager.AppSettings["ConnString"]));
        //cmd.CommandType = Data.CommandType.StoredProcedure
        cmd.Connection.open();

        sqlDataReader ddlValues = default(sqlDataReader);
        ddlValues = cmd.ExecuteReader();

        //if (!IsPostBack) {
            ddlDrillDown.Items.Clear();
            ddlDrillDown.DataSource = ddlValues;
            ddlDrillDown.DataValueField = "content_id";
            ddlDrillDown.DataTextField = "content_title";
            ddlDrillDown.DataBind();
            //set the default value for the drop down
            ListItem Item = new ListItem();
            Item.Text = "Select a Physician's Name";
            Item.Value = "0";
            //Item.Selected = True
            ddlDrillDown.Items.Insert(0,Item);
        //}
    cmd.Connection.Close();
    cmd.Connection.dispose();
    }

    public void PopulateSpecialty() {
        sqlCommand cmd = new sqlCommand("getSpecialties",new sqlConnection(ConfigurationManager.AppSettings["ConnString"]));
        cmd.Connection.open();

        sqlDataReader ddlValues = default(sqlDataReader);
        ddlValues = cmd.ExecuteReader();

        //if (!IsPostBack) {
            ddlDrillDown.Items.Clear();
            ddlDrillDown.DataSource = ddlValues;
            ddlDrillDown.DataValueField = "content_id";
            ddlDrillDown.DataTextField = "content_title";
            ddlDrillDown.DataBind();
            //set the default value for the drop down
            ListItem Item = new ListItem();
            Item.Text = "Select a Specialty";
            Item.Value = "0";
            ddlDrillDown.Items.Insert(0,Item);
        //}
        cmd.Connection.Close();
        cmd.Connection.dispose();
    }

    public void PopulateLocation() {
        sqlCommand cmd = new sqlCommand("getLocations",new sqlConnection(ConfigurationManager.AppSettings["ConnString"]));
        cmd.Connection.open();

        sqlDataReader ddlValues = default(sqlDataReader);
        ddlValues = cmd.ExecuteReader();

        //if (!IsPostBack) {
            ddlDrillDown.Items.Clear();
            ddlDrillDown.DataSource = ddlValues;
            ddlDrillDown.DataValueField = "content_id";
            ddlDrillDown.DataTextField = "content_title";
            ddlDrillDown.DataBind();

            //set the default value for the drop down
            ListItem Item = new ListItem();
            Item.Text = "Select a Location";
            Item.Value = "0";
            ddlDrillDown.Items.Insert(0,Item);
        //}
        cmd.Connection.Close();
        cmd.Connection.dispose();
    }

    public void ddlMain_SelectedindexChanged(object sender,System.EventArgs e) {
        switch(ddlMain.Selectedindex) {
            case 0:
                PopulatePhysician();
                break;
            case 1:
                PopulateLocation();
                break;
            case 2:
                PopulateSpecialty();
                break;
        }
    }
}

我试图添加到上面的功能是,当用户从ddlMain下拉列表中选择一个选项,根据选项刷新ddlDrillDown下拉列表而不重新加载页面.

我怎样才能实现它?

更新:

<asp:ScriptManager ID="ScriptManager" 
                               runat="server" />
            <asp:UpdatePanel ID="UpdatePanel1" 
                             UpdateMode="Conditional"
                             runat="server">
                <ContentTemplate>
                    <asp:DropDownList AutopostBack="True" OnSelectedindexChanged="ddlMain_SelectedindexChanged" ClientIDMode="Static" ID="ddlMain"runat="server" AppendDataBoundItems="true">
                        <asp:ListItem Text="BY PHYSICIAN" Value="0" Selected="True" />
                        <asp:ListItem Text="BY LOCATION" Value="1" />
                        <asp:ListItem Text="BY SPECIALTY" Value="2" />
                    </asp:DropDownList>
                    <br /><br />
                    <asp:DropDownList ClientIDMode="Static" ID="ddlDrillDown"runat="server" AppendDataBoundItems="true">
                    </asp:DropDownList>
                    </ContentTemplate>
            </asp:UpdatePanel>

解决方法

使用AJAX.将两个下拉控件放在UpdatePanel中,并在页面中打开Form标签后添加一个ScriptManager(如果尚未存在)

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

我之前使用IWebDriver控制IE进行测试.但是IWebDriver和IWebElement支持的方法非常有限.我发现属于Selenium命名空间的ISelenium / DefaultSelenium非常有用.如何在不安装Selenium Server的情况下使用它们来控制IE?

这是DefaultSelenium的构造函数:

ISelenium sele = new DefaultSelenium(**serveraddr**,**serverport**,browser,url2test);
sele.Start();
sele.open();
...

似乎我必须在创建ISelenium对象之前安装Selenium Server.

我的情况是,我正在尝试使用C#Selenium构建一个.exe应用程序,它可以在不同的PC上运行,并且不可能在所有PC上安装Selenium Server(你永远不知道哪个是下一个运行应用程序).

有没有人知道如何在不安装服务器的情况下使用ISelenium / DefaultSelenium?
谢谢!

解决方法

在不使用RC Server的情况下,Java中有一些解决方案:

1)对于selenium浏览器启动:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setbrowserName("safari");
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"),new URL("http://www.google.com/"),capabilities);
WebDriver driver = new RemoteWebDriver(executor,capabilities);

2)对于selenium命令:

// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();

// A "base url",used by selenium to resolve relative URLs
 String baseUrl = "http://www.google.com";

// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl);

// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q","cheese");
selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();

//Finally,close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise,the JVM will continue running after
//the browser has been closed.
selenium.stop();

描述于此:http://seleniumhq.org/docs/03_webdriver.html

谷歌在C#中有类似的东西.没有其他方法可以实现这一目标.

GitHub如何在不重新加载页面的情况下更改URL?

GitHub如何在不重新加载页面的情况下更改URL?

转到任何GitHub
页面,然后单击任何目录/文件,并观察URL的更改方式,但仅更新页面的一部分。没有整个页面重新加载。

我如何使用jQuery做类似的事情?

这对大多数浏览器都有效吗(我使用的是Chrome)?

答案1

小编典典

他们使用历史记录API,或者专门使用history.pushState()

您可以使用它,不需要jQuery,但是有一些插件,例如history.js。

这适用于大多数浏览器,即Chrome,Safari和Firefox。IE10及以上版本支持此功能。在较旧的IE中,您可以使用哈希(window.location.hash)退回。

GitHub也对此发表了博客。

javascript – 如何在不重新加载页面的情况下更改地址栏中的URL?

javascript – 如何在不重新加载页面的情况下更改地址栏中的URL?

Shopify如何做到这一点?转到他们的网站,点击功能链接,您会看到浏览器地址栏中的URL显示:

http://www.shopify.com/tour/sell-online

然后单击任何子链接,您将看到地址栏中的URL更改而不使用哈希,并且没有页面翻转.

我不认为他们使用ajax来更改内容,因为它似乎都包含在页面上的隐藏div中,但无论如何,您显然可以使用客户端技巧更改URL.感谢您的帮助?

解决方法

您使用新的HTML5历史记录API来推送新状态.

这是the MDN documentation和a good tutorial.

请注意,执行此操作通常很痛苦(您必须正确管理应用程序的状态)和it doesn’t work with IE9.它几乎总是与ajax结合使用:即使整个页面未重新加载或更改,也能让动态加载的内容成为可收藏的解决方案.

今天关于Java Selenium:如何在不首先加载页面的情况下获取网页的HTML?selenium获取js加载后的页面的分享就到这里,希望大家有所收获,若想了解更多关于c# – 如何在不重新加载页面的情况下刷新下拉列表?、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、GitHub如何在不重新加载页面的情况下更改URL?、javascript – 如何在不重新加载页面的情况下更改地址栏中的URL?等相关知识,可以在本站进行查询。

本文标签: