Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Go through hidden elements one by one.

Veronica

Coder
I have a few elements I want to click with selenium. The elements are hidden and I'm using the format right. Consequently, I'm looking for a workaround to iterate the function. I have the function in curly braces with the 'f' format to read the function. In order to see the element I have to switch the format to 'u'. The 'u' format only allows you to find hidden elements. Unfortunately, it does not read functions within curly braces. Which makes things more difficult to change the value within the variable. Also, there is no way to use both 'u' and 'f'. My question is if there is a workaround to achieve this task.
Code:
browser.find_element(By.XPATH, f"/html/body/app-root/ac-site-layout/div[{number}]")

error - cannot locate element

Code:
browser.find_element(By.XPATH, u"/html/body/app-root/ac-site-layout/div[{number}]")

error - can only hold one argument
 
I have a few elements I want to click with selenium. The elements are hidden and I'm using the format right. Consequently, I'm looking for a workaround to iterate the function. I have the function in curly braces with the 'f' format to read the function. In order to see the element I have to switch the format to 'u'. The 'u' format only allows you to find hidden elements. Unfortunately, it does not read functions within curly braces. Which makes things more difficult to change the value within the variable. Also, there is no way to use both 'u' and 'f'. My question is if there is a workaround to achieve this task.
Code:
browser.find_element(By.XPATH, f"/html/body/app-root/ac-site-layout/div[{number}]")

error - cannot locate element

Code:
browser.find_element(By.XPATH, u"/html/body/app-root/ac-site-layout/div[{number}]")

error - can only hold one argument
Hey there,

Quick question: does your script need to be specifically be all in python?
 
I think the first thing we need is the website you are trying to use Selenium on and what you are trying to do.

The reason i ask is if you are trying to go through each hidden div you could instead do :-

Python:
browser.find_elements(By.XPATH, "/html/body/app-root/ac-site-layout/div")

and this would get all of the divs for you
 

New Threads

Buy us a coffee!

Back
Top Bottom