Mallik
Mallik

Reputation: 709

Unable to click on the Submit button using selenium webdriver

I have a submit button on my UI page but I am not able to click on that button even if I take the XPath of that. Below is the UI code for button

<input type="submit" class="btn btn-primary btn-lg col-sm-2" value="Submit">

but the XPath i am getting is

//*[@id="form"]/div[5]/input 

So please provide me some inputs to select the button. I also need to scroll down the page a bit as the button is also not visible on the page.

Upvotes: 2

Views: 4646

Answers (3)

noor
noor

Reputation: 3004

u may try by using cssSelector like below:

driver.findElement(By.cssSelector(".btn.btn-primary.btn-lg.col-sm-2"));

for this, class "btn.btn-primary.btn-lg.col-sm-2" must be unique.

if the element is not visible in the screen, than use like below:

JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement elem =  driver.findElement(By.cssSelector(".btn.btn-primary.btn-lg.col-sm-2"));

 //this line will scroll down to make element visible
js.executeScript("window.scrollTo(" + elem.getLocation().x + "," +(elem.getLocation().y- 100) + ");");

than click on that element:

elem.click();

Upvotes: 1

nikhil udgirkar
nikhil udgirkar

Reputation: 357

You can try following xpath

//input[@class='btn btn-primary btn-lg col-sm-2']

this should work

Upvotes: 0

Rajnish Kumar
Rajnish Kumar

Reputation: 2938

Hi please use this xpath it will work

//*[@id='form']/div[5]/input // if nodes are correct then

if yor page has got only on tag with attribute value value="Submit" then

//*[@value='Submit']

Upvotes: 0

Related Questions