-2

I am facing problem in writing automation script for check box for website, please go through website link and i am sharing my code please go through this code.

http://automationpractice.com/index.php?controller=authentication&back=my-account

Please go through below screen shot Where i did red circle over check box, i want xpath for that.enter image description here

5
  • 1
    Please elaborate what seems to be the problem and include a stack trace of the error you are getting.
    – Moro
    Commented Feb 5, 2020 at 12:34
  • please open that website u will get account creation form, in that form two check box will comes, but m not able to click on that check box.
    – sushen
    Commented Feb 5, 2020 at 12:38
  • 1
    Please edit your question and make the following changes: remove your personal data from the code and replace it with fake data; add the error you receive when you try to run your code; and add comments to your code to explain what you are looking for in the absolute XPaths.
    – Kate Paulk
    Commented Feb 5, 2020 at 12:45
  • 1
    you can use the id for both those checkpoints! why you need xpath, but here you go //*[@id="optin"] and //*[@id="newsletter"]
    – PDHide
    Commented Feb 5, 2020 at 13:18
  • 1
    What have you actually tried for an xpath or css selector? What does your code look like?
    – Lee Jensen
    Commented Feb 5, 2020 at 23:33

3 Answers 3

3

I went through the URL provided by you. Here is the XPath for above two checkboxes:

  1. Sign up for our newsletter!
    XPath: //div[contains(@id,'uniform-newsletter')]/span[1]

  2. Receive special offers from our partners!
    XPath: //div[contains(@id,'uniform-optin')]/span[1]

Here is the HTML Code:

enter image description here

Let me know if it works for you.

1
  • Appreciate your answer i will check your code and soon come to you.
    – sushen
    Commented Feb 7, 2020 at 4:48
1

Xpath:

//input[@id='newsletter']

CSS

input#newsletter

You can try out the below code to click. This code is in Java.

WebElement signUpNewsLetter = driver.findElement(By.xpath("//input[@id='newsletter']")); 
//You can check the state of the element
signUpNewsLetter.click();
//You can then check whether it's selected or not
boolean isSelected = signUpNewsLetter.isSelected();

0

Here is the XPath for above both checkboxes.

Xpath 1. Sign up for our newsletter!

//*[@id="newsletter"] or use below one

/html/body/div/div[2]/div/div[3]/div/div/form/div[1]/div[7]/label

Xpath 2. Receive special offers from our partners!

//*[@id="optin"] or use below one

/html/body/div/div[2]/div/div[3]/div/div/form/div[1]/div[8]/label

I hope it is helpful to you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.