简体   繁体   English

如何在Selenium中单击Javascript按钮

[英]How to click on the Javascript button in Selenium

In the web page there are some rows with same button name. 在网页中,有些行具有相同的按钮名称。 Xpath is not working for me since xpath id name is same for all rows.xpath id is //*[@id="btnChangeStatusThisOrder"] Xpath不适用于我,因为所有行的xpath ID名称都相同。xpathID为// * [@@ id =“ btnChangeStatusThisOrder”]

This is the code for one row. 这是一行的代码。 I have to click on this specific button from this code. 我必须单击此代码中的此特定按钮。 How can I write code for this Javascript button. 如何为该Javascript按钮编写代码。 Also ID btnChangeStatusThisOrder is available for many rows. ID btnChangeStatusThisOrder也可用于许多行。

<a href="javascript: handleOrderStatusChange('251')" id="btnChangeStatusThisOrder" class="actionBtn">Go</a> 

If you are looking for this specific button your XPath should be something like this: 如果您正在寻找此特定按钮,则您的XPath应该是这样的:

GoButtonXpath = "//a[@id='btnChangeStatusThisOrder' and text()='Go']"

If you are looking to click a few of the buttons you can get them with findElements , not findElement . 如果要单击一些按钮,可以使用findElements而不是findElement来获得它们。

Hope this helpes you! 希望对您有帮助!

Try using following code for javascript button. 尝试对javascript按钮使用以下代码。

JavascriptExecutor JS=(JavascriptExecutor)driver;

        JS.executeScript("document.getEementByXpath('//a[@id='btnChangeStatusThisOrder']).click()'", button);

hope this help!! 希望有帮助!!

This will work. 这将起作用。

WebElement button = driver.findElement(By.Xpath("xpath of the button")); WebElement按钮= driver.findElement(By.Xpath(“按钮的xpath”));

JavascriptExecutor JS=(JavascriptExecutor)driver; JavascriptExecutor JS =(JavascriptExecutor)驱动程序; js.executeScript("arguments[0].click();", button); js.executeScript(“ arguments [0] .click();”,button);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM