0

The part I'm trying to click:

<ul class="btns right">
<li><a href="javascript:void(0)" onclick="hr_expand_event_tab_all(&quot;&quot;)" class="expand-all" id="btn_expand_all_10580503">View All Cards</a></li>
</ul>

Pretty straightforward I thought. But I seem to be missing something.

Question is now updated a little further down the page. The xpath isn't the problem I've tried with corrected xpath and it's the same as using the class name. CSS was hiding several versions of the button but a common.exception is being thrown on the ones it does actually find with xpath or the class name.

I've checked the page is loaded properly and the element is there. I have a check to wait until the full page is loaded and it screenshots to be sure.

loadbutton = Driver.find_element_by_xpath("//a[@class='expand-all']")

Gives:

<class 'selenium.common.exceptions.ElementNotVisibleException'>

So I tried to find an onclick with the anchor:

loadbutton = Driver.find_element_by_xpath("//li[contains(@onclick, 'View All Cards')]")

With the same outcome. I've tried a bit of regex to catch the id variations as well but I'm not sure where I'm going wrong here. There's an onlick and it is loaded but I can't see to find it.

I'd appreciate anyone who can show me what I'm doing wrong on this one.

/Update:

Turns out there's multiple versions of the button some are visible and others are not.

I looped:

loadbutton = Driver.find_elements_by_xpath("//a[@class='expand-all']")
for button in loadbutton:
  print "button found"

It turned up multiple results. The earlier ones are hidden but the ones at the end are certainly showing on my browser and the screenshot. So I expected the early ones to fail and added a .click() with a try: except: and they all failed still. Didn't expect that.

Further update:

So I ran this:

loadbutton = Driver.find_elements_by_xpath("//a[@class='expand-all']")
for button in loadbutton:
  print "button found"
  try:
    button.click()
  except:
    e = sys.exc_info()[0]
    print e

The first couple gave me this:

<class 'selenium.common.exceptions.ElementNotVisibleException'>

OK expected the CSS is hiding it. The last two which are displaying gave this:

<class 'selenium.common.exceptions.WebDriverException'>

So it can see them. It won't click them. "Common exception" doesn't seem overly helpful.

16
  • Seems like the button is hidden using css. can you see the button when your getting this page in your browser ? Commented May 9, 2016 at 11:42
  • //*/a[contains(text(), 'View All Cards')] try this xpath, your xpath construction seems wrong Commented May 9, 2016 at 11:47
  • Why all this bother with xpath when the button has an id? Commented May 9, 2016 at 11:49
  • @e4c5 Considering the number in the id I'm guessing it might be an auto-generated id. Commented May 9, 2016 at 11:51
  • ID seems to be dynamic..framework generated..... Commented May 9, 2016 at 11:51

1 Answer 1

2

Try this xpath (updated with code block SO site removed my *)

//*[contains(concat(' ', @class, ' '), ' btns right ')]//*[contains(concat(' ', @class, ' '), ' expand-all ') and contains(text(), 'View All Cards')]

Provide some wait for the element to be clickable(implicit is recommended).

I have Used Only for java , But I refered here for python here it may help!!

from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
button = wait.until(EC.element_to_be_clickable((By.XPATH,'//*[contains(concat(' ', @class, ' '), ' btns right ')]//*[contains(concat(' ', @class, ' '), ' expand-all ') and contains(text(), 'View All Cards')]')))
button.click()


Even if the above thing fails, try this

form these links link1 and link2

driver.execute_script("document.getElementsByClassName('expand-all')[0].click();")

inject an artificial CLICK on the desired element, remove(comment) all other codes

May be ur app falls under link2 OP :)

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

6 Comments

Thanks for the suggestion. It's throwing InvalidSelectorException and that xpath is way beyond me so I've no chance of debugging. That said just updated the question again I don't think the problem is finding them looping through the ones hidden by css fail because they're not found when it comes to clicking but the later ones just throw a common exception. That says to me it's finding them using class just isn't able to click them for some "common" reason.
Works and impressive xpath but gets the exact same results as using the class name unfortunately.
Tried it. Literally left it on a 10 minute wait at one point. It's rendered on the page it's finding all the buttons, exception handling the ones css hides and just throwing a common.exception to the ones it can see but for some reason doesn't want to click.() I haven't seen anything like this before.
Cheers for the suggestion though.
You're a wonderful human being. Worked a charm I never knew that was a thing.
|

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.