2

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.

3 Answers 3

1

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();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply i treid but i am getting the following error [Element with cssSelector: .btn.btn-primary.btn-lg.col-sm-2 was found -----unknown error: Element is not clickable at point (467, 591). Other element would receive the click:
This worked for me! We were trying some automated browsing on coursera.com. Many thanks!
0

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']

1 Comment

@ raj NishKumar Can you just help me out with a page scroll down code as well i tried using java script JavascriptExecutor javascript = (JavascriptExecutor) driver; javascript.executeScript("window.scrollBy(0,900)", ""); Its not working
0

You can try following xpath

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

this should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.