1

I'm using Selenium Webdriver (Chrome & Firefox) with Java .

After making all kind of actions, I came across a regular source code like this :

<input type="button" value="yoyo" class="btn" onClick="SubmitForm(this, 'XYZ','_blank')" >

and I need to push the button.. but before pushing the button (regularly), I need to change the "XYZ" to "ABC". Is there any way to do that?

Or maybe creating a new button or a form and then push it?

Or even use javascript somehow.. anything will do.

I could not find any information on how to do this, I will be thankful for your help.

Tajkia Rahman Toma
  • 472
  • 1
  • 5
  • 16
Sahar Millis
  • 801
  • 2
  • 13
  • 21
  • Usually one would use Selenium to interact with a web page as presented from the server. Are you asking about how to manipulate the content of the page while using Selenium, so that Selenium can then operate on the modified page? – Greg Chabala Jul 12 '16 at 04:44
  • Yep .. As I mentioned, I have to press a button when one of the values is different. I know this is not the goal of the tool, but if it can do that it will help me a lot. – Sahar Millis Jul 12 '16 at 04:58

2 Answers2

1

You'll want to use the JavascriptExecutor as described here: https://stackoverflow.com/a/8476765/62462

WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('//id of element').setAttribute('onClick', 'SubmitForm(this, \'ABC\',\'_blank\')')");

You might need to find the input element via XPath if it doesn't have an id.

Community
  • 1
  • 1
Greg Chabala
  • 1,125
  • 2
  • 23
  • 35
1

You can change it during runtime automation then click using JavascriptExecutor as below :-

WebElement el = driver.findElement(By.className("btn"))

((JavascriptExecutor) driver).executeScript("arguments[0].setAttribute('onClick', arguments[1]);arguments[0].click();", el, "SubmitForm(this, 'ABC','_blank')");

Note:- This will not effect as permanently solution. this effect will work on the page until the page not refresh.

Hope it will work..:)

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73