Expected conditions with selenium
It's just that your XPath expression is incorrect, should be:
//br
Or, you can use the "tag name" locator:
wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'br')))
As a side note, I'm not sure what your intentions are, but I've never seen a case where someone would rely on a presence of a br
tag in test automation or web-scraping. It doesn't necessarily mean you are doing something wrong, but make sure there is a solid reason for that.
user3078335
Updated on June 04, 2022Comments
-
user3078335 almost 2 years
How do i check if a
br
tag is present in HTML using expected conditions. This is the HTML code:<br> <a href="member.php?u=12455" rel="nofollow">Smatta</a> <a>, </a> <a href="member.php?u=14305" rel="nofollow">Nyunyu</a> <a>, </a> <a href="member.php?u=20892" rel="nofollow">moyo</a> <a>, </a> <a href="member.php?u=21040" rel="nofollow">Masikini_Jeuri</a> <a>, </a> <a href="member.php?u=27429" rel="nofollow">Job K</a> <a>, </a> <a href="member.php?u=38124" rel="nofollow">Adoe</a> <a>, </a> <a href="member.php?u=39196" rel="nofollow">enhe</a> <a></a>
This is my code.
wait = WebDriverWait(browser, 10) wait.until(EC.visibility_of_element_located((By.XPATH, '//<br>')))
Full code.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC browser = webdriver.PhantomJS() browser.maximize_window() browser.get("http://www.jamiiforums.com/kenyan-news/225589-kenyan-and-tanzanian-surburbs.html") username = browser.find_element_by_id("navbar_username") password = browser.find_element_by_name("vb_login_password_hint") username.send_keys("MarioP") password.send_keys("codeswitching") browser.find_element_by_class_name("loginbutton").click() wait = WebDriverWait(browser, 20) wait.until(EC.visibility_of_element_located((By.XPATH, '//h2[contains(., "Redirecting")]'))) wait.until(EC.title_contains('Kenyan & Tanzanian')) wait.until(EC.visibility_of_element_located((By.ID, 'postlist'))) browser.find_element_by_xpath('//div[@class="vbseo_liked"]/a[contains(@onclick, "return vbseoui.others_click(this)")]') browser.find_element_by_class_name("vbseo_liked").click() wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'br'))) print (browser.page_source) print 'success!!' browser.close()
The reason I am doing that is because the br tag only appears after a link has been clicked. I am trying to get the page source after the click action, but it gives me the page source before the click action. I wanted to check the presence of the br tag before i get the page source.
This is the error it prints out.
File "sele.py", line 29, in wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'br')))