Home > Software design >  I cannot find a "button onclick" element using Selenium and Python
I cannot find a "button onclick" element using Selenium and Python

Time:10-20

I am automating a process using Selenium and python. Right now, I am trying to click on a button in a webpage (sorry I cannot share the link, since it requires credential to login), but there is no way my code can find this button element. I have tried every selector (by id, css selector, xpath, etc.) and done a lot of googling, but no success.

Here is the source content from the web page:

<button onclick="javascript: switchTabs('public');" aria-selected="false" itemcount="-1" type="button" title="Public Reports" dontactassubmit="false" id="public" aria-label="" > Public Reports </button>

I also added a sleep command before this to make sure the page is fully loaded, but it does not work.

Can anyone help how to select this onclick button? Please let me know if you need more info.

Edit: you can take a look at this picture to get more insight (https://ibb.co/cYXWkL0). The yellow arrow indicates the button I want to click on.

CodePudding user response:

I don't know why this may be happening, but you could try:

  • waiting for the element to load in (WebDriverWait or time.sleep)
  • scrolling down (if the element is not visible)

Could you please provide the error message and a bit more html around the button?

CodePudding user response:

The element you trying to click is inside an iframe. So, you need to switch driver into the iframe content before accessing elements inside it.
I can't give you a specific code solution since you didn't share a link to that page, even not all that HTML block. You can see solutions for similar questions here or enter link description here. More results can be found with google search

  • Related