Weird Python Selenium Button Click Behaviour -
the part i'm trying click:
<ul class="btns right"> <li><a href="javascript:void(0)" onclick="hr_expand_event_tab_all("")" class="expand-all" id="btn_expand_all_10580503">view cards</a></li> </ul>
pretty straightforward thought. seem missing something.
question updated little further down page. xpath isn't problem i've tried corrected xpath , it's same using class name. css hiding several versions of button common.exception being thrown on ones find xpath or class name.
i've checked page loaded , element there. have check wait until full page loaded , screenshots sure.
loadbutton = driver.find_element_by_xpath("//a[@class='expand-all']")
gives:
<class 'selenium.common.exceptions.elementnotvisibleexception'>
so tried find onclick anchor:
loadbutton = driver.find_element_by_xpath("//li[contains(@onclick, 'view cards')]")
with same outcome. i've tried bit of regex catch id variations i'm not sure i'm going wrong here. there's onlick , loaded can't see find it.
i'd appreciate can show me i'm doing wrong on one.
/update:
turns out there's multiple versions of button visible , others not.
i looped:
loadbutton = driver.find_elements_by_xpath("//a[@class='expand-all']") button in loadbutton: print "button found"
it turned multiple results. earlier ones hidden ones @ end showing on browser , screenshot. expected ones fail , added .click() try: except: , failed still. didn't expect that.
further update:
so ran this:
loadbutton = driver.find_elements_by_xpath("//a[@class='expand-all']") 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 css hiding it. last 2 displaying gave this:
<class 'selenium.common.exceptions.webdriverexception'>
so can see them. won't click them. "common exception" doesn't seem overly helpful.
try xpath (updated code block site removed *)
//*[contains(concat(' ', @class, ' '), ' btns right ')]//*[contains(concat(' ', @class, ' '), ' expand-all ') , contains(text(), 'view cards')]
provide wait element clickable(implicit recommended).
i have used java , refered here python here may help!!
from selenium.webdriver.support import expected_conditions 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 ') , contains(text(), 'view cards')]'))) button.click() if above thing fails, try
form these links link1 , link2
driver.execute_script("document.getelementsbyclassname('expand-all')[0].click();")
inject artificial click on desired element, remove(comment) other codes
may ur app falls under link2 op :)
Comments
Post a Comment