当我们不知道单击什么时如何获取硒中的clicked元素

时间:2018-12-24 12:44:43

标签: selenium

我正在遵循以下oc代码->

进行单击
actions.moveToElement(objDriver.findElement(By.id("id_popcode")),coordinates.getX(),coordinates1.getY()-1).doubleClick().build().perform(); 

基本上,我在我们的应用程序中双击一个位置(x,y)。单独地,我们不能单击该特定元素,因为必须在特定(x,y)本身上单击它。因此,我想获取喜欢id, classname的那个单击元​​素的属性(我使用上面提到的action命令单击它)。有人可以帮我这个...有点卡在这里..........

2 个答案:

答案 0 :(得分:0)

如果在该特定坐标处有任何特定文本,请使用它。我也遇到了同样的问题,我需要双击文本为0.00%的单元格。我首先使用文本完成了悬停操作,然后双击完成

由于这些天我正在量角器上工作,因此请忽略语法问题

browser.driver.actions().mouseMove(driver.findElement(by.xpath("//*[text()='00')]").build().perform();

然后执行点击

仍然有问题,请检查是否具有ng-click之类的任何属性,这对于获取特定位置的坐标很有帮助。请始终共享HTML代码,以帮助我们更深入地检查

答案 1 :(得分:0)

编辑:

尝试使用 public partial class NewSongUI : Form { public string songtitle; private string songtexter; private string songcomposer; private string songtext; public NewSongUI() { InitializeComponent(); } private void NewSongUI_FormClosing(object sender, FormClosingEventArgs e) { MSongtitle = TBTitle.Text; MSongtexter = TBTexter.Text; MSongcomposer = TBMusic.Text; MSongtext = TBSongText.Text; } } 执行.elementFromPoint()以按坐标获取元素

JavascriptExecutor

旧:

您在JavascriptExecutor js = (JavascriptExecutor)driver; WebElement theElement = (WebElement)js.executeScript("return document.elementFromPoint(arguments[0], arguments[1])", coordinates.getX(), coordinates1.getY()-1); System.out.println(theElement.getAttribute("tagName")); System.out.println(theElement.getAttribute("class")); 中使用负值,这意味着元素上方的坐标,可能元素的getY()-1parent尝试使用xpath进行选择

preceding-sibling