0

I have a website ,in which just wish to click and open a collapse/open window .My condition is only if this button was not open then open it otherwise proceed for next operation. What is the response or key i need to add in selenium python code to do this operation.

May be this will help for more clarity.

Do not Click again this Box as it is already open Do not click as it is clicked click and open as it is closed

The X path of the particular button is /html/body/div1/div/div2/div/san/svg and the code i used for click is

driver.find_element_by_xpath('/html/body/div[1]/div/div[2]/div/san/svg').click()

All i want to do it ,if not previously this is clicked then only click,what parameter or option i need to use in selenium python to do this.

Adding More Details when the Box is Closed this is the "Elements code i see"

Element code when Box in closed state

When in Box open state this is the "element code" i get In Box open state

5
  • after clicking it must have changed in html code part for that icon. You can write a try except for that. Inspect the element and check what changes has been . Commented Nov 23, 2020 at 12:11
  • @Pygirl Any code snippet example ? Commented Nov 23, 2020 at 12:12
  • check this: stackoverflow.com/a/49827874/6660373 Commented Nov 23, 2020 at 12:14
  • @Pygirl the html code is added for both actions, could you help me with a code template,only if the box is in closed state by the selenium click and open else ignore this click step.Thank you Commented Nov 23, 2020 at 16:25
  • You have class widget pages which is initially hidden. You can use it. Selenium has a function which trigger the code when it founds the element. You can use it. Commented Nov 26, 2020 at 8:22

1 Answer 1

-1

You will need a mechanism to check if the box is open, there are a few ways to do this.

  1. Check for the unique element that only exists within the box, such as the elements with id or class in the box. If they are present, the box is open and thus don't click again.

  2. The first approach may not work for every website since some just use hide or similar class to hide the box. For these cases, check if the elements inside the box have the hide class, if they don't, the box is open and don't click it.

  3. Check the button to see if it has a unique class/text for defining open and close, such as the colour of the button. From your photo, it turned blue after the box is open, maybe you can try to inspect if that's the case and use that as a way to check if the box is open.

Sign up to request clarification or add additional context in comments.

1 Comment

i have added the html code in both action ,could you help me with a code template,only if the box is in closed state by the selenium click and open else ignore this click step.Thank you

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.