请帮帮我。 Selenium没有点击元素,元素是可点击的(selenium不会产生异常)。 我尝试使用Id,css,xpath定位器,什么都没有帮助我。
我该怎么做才能确定我的问题?
Java代码示例。
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
var child = new Child();
var serializesObject = JsonConvert.SerializeObject(child);
var deserializedObject = JsonConvert.DeserializeObject(serializesObject, typeof(Child));
}
}
public abstract class Abstract
{
public int Prop1 { get; set; }
public readonly string Prop2;
public List<string> Prop3 { get; set; }
public int[] Prop4 { get; set; }
public abstract void Hey();
public Abstract()
{
Prop1 = 1;
Prop2 = "2";
Prop3 = new List<string>();
Prop4 = new int[4];
}
}
public class Child : Abstract
{
public readonly string Prop5;
public Child()
{
Prop5 = "5";
}
public override void Hey()
{
throw new NotImplementedException();
}
}
}
答案 0 :(得分:1)
似乎您尝试与<svg>
元素内的对象进行交互。如果是这样,您无法使用click()
方法管理其子元素。
请改为尝试:
WebElement svgObject = driver.findElement(By.xpath("//polygon[@id='sector-1:canvas']"));
Actions builder = new Actions(driver);
builder.click(svgObject).build().perform();
答案 1 :(得分:0)
使用以下XPath:
WebElement sector = webDriver.findElement(By.xpath("//g[@id='sector-1']/polygon"));
sector.click();
OR
WebElement sector = webDriver.findElement(By.xpath("//polygon[@id='sector-1:canvas']"));
sector.click();
答案 2 :(得分:0)
我决定我的问题。
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"sector-2:canvas\"]")));
WebElement svgObject = webDriver.findElement(By.xpath("//*[@id=\"sector-2:canvas\"]"));
Actions builder = new Actions(webDriver);
builder.click(svgObject).build().perform();