使用java中的selenium web驱动程序从div获取文本值

时间:2016-06-16 15:41:31

标签: java selenium selenium-webdriver

我有这个HTML:

"hello"

我希望只有 "hello world" 文字,不包含 subject = this.driver.findElement(By.xpath("//div[@class = 'b-datalist__item__subj']")).getText(); 。我写这段代码:

"hellohello world"

但在控制台输出中,我看到 $(function() { //example data var data = [{ label: 'Velocity', color: '#93cc67', data: [ [1415165113000, 0], [1415165202000, 13], [1415165221000, 19], [1415165239000, 22], [1415165254000, 23], [1415165271000, 24] ] }]; //non data-dependent options var options = { canvas: true, series: { lines: { show: true }, points: { show: true } }, xaxis: { mode: "time", timezone: "browser" }, yaxis: {}, legend: { type: "canvas", position: "ne" }, grid: { clickable: true, hoverable: true }, zoom: { interactive: true }, pan: { interactive: true, cursor: "move" } }; //calculate the min/max and ranges to set the zoom and pan limits var minx = null; var maxx = null; var miny = null; var maxy = null; var numvals = 0; //calculate min, max and max num of values for (var a in data) { for (var d in data[a].data) { if ((minx === null) || (data[a].data[d][0] < minx)) minx = parseFloat(data[a].data[d][0]); if ((maxx === null) || (data[a].data[d][0] > maxx)) maxx = parseFloat(data[a].data[d][0]); if ((miny === null) || (data[a].data[d][1] < miny)) miny = parseFloat(data[a].data[d][1]); if ((maxy === null) || (data[a].data[d][1] > maxy)) maxy = parseFloat(data[a].data[d][1]); } if (data[a].data.length > numvals) numvals = data[a].data.length; } if (minx === null) minx = 0; if (maxx === null) maxx = 0; if (miny === null) miny = 0; if (maxy === null) maxy = 0; //calculate ranges var xrange = maxx - minx; var yrange = maxy - miny; //apply small margin var auxxmargin = xrange * 0.02; var auxymargin = yrange * 0.02; options.xaxis.min = minx - auxxmargin; options.xaxis.max = maxx + auxxmargin; options.yaxis.min = miny; options.yaxis.max = maxy + auxymargin; //xaxis zoom range from 1 value to all values options.xaxis.zoomRange = [xrange / numvals, xrange + (auxxmargin * 2)]; //xaxis pan range from min value to max value options.xaxis.panRange = [options.xaxis.min, options.xaxis.max]; //trying to disable the yaxis zoom and pan options.yaxis.zoomRange = [0, 0]; options.yaxis.panRange = [0, 0]; var plot = $.plot("#placeholder", data, options); }); 。我该如何解决?

2 个答案:

答案 0 :(得分:1)

您必须从span的完整文字中“减去”div内的文字。类似的东西:

String outsideText = driver.findElement(By.xpath("//div")).getText();
String insideText = driver.findElement(By.xpath("//span")).getText();
String yourText = outsideText.replace(insideText, "");

根据您的具体情况调整XPath。

答案 1 :(得分:-1)

使用以下作为xpath:

public class Account
{
    // One to one to one relationship (shared PK)
     public int Id { get; set; }

     // One to one to one relationship (shared PK)
     public virtual Operation Operation { get; set; }

    // One to many relationship foreign Key
    [InverseProperty("AccountForList")]
     public virtual List<Operation> Operations { get; set; }
   }

   public class Operation
   {
    // One to one to one relationship (shared PK)
    [ForeignKey("Account")]
     public Int32 Id { get; set; }

     // One to one to one relationship (shared PK)
     public virtual Account Account { get; set; }

     // One to many relationship foreign Key
     public Int32? AccountForListId { get; set; }

     // One to many relationship foreign Key
     [ForeignKey("AccountForListId")]
     public virtual Account AccountForList { get; set; }
     }