python - Not sure what is causing selenium timeouts -
so tried create suite in python run tests on twitter share buttons. used "switch_to_frame" function navigate iframe , select button. here code
class entertainmentsocialmedia(coretest): def testentertainmenttwitter(self): d = self.driver d.get(config.host_url + '/testurl') social_text = 'follow @twitterhandle' print "locating amusement vertical social share button" time.sleep(3) d.switch_to_frame(d.find_element_by_css_selector('#twitter-widget-0')) social_button = d.find_element_by_xpath('//*[@id="l"]').text self.asserttrue(str(social_text) in str(social_button)) print social_button d.close()
my concern multiple tests in suite, selenium timeout. there wrong code or can improved? ideally i'd them robust possible , avoid timeouts. thanks!
better wait frame explicitly:
from selenium.webdriver.common.by import selenium.webdriver.support.ui import webdriverwait selenium.webdriver.support import expected_conditions ec ... d.get(config.host_url + '/testurl') frame = webdriverwait(d, 10).until( ec.presence_of_element_located((by.id, "twitter-widget-0")) ) d.switch_to_frame(frame)
this wait 10 seconds , throw timeoutexception
. default, check presence of frame
every 500 ms.
hope helps.
python selenium saucelabs
No comments:
Post a Comment