Issue
I have this list that I need to cycle through until I reach the munprod DB on the host server ending with "01". I'm using the code below and apparently have a syntactical error that I cannot figure out because it's dropping into the code for the if statement as if it were true, but it's doing it for host = '02' and not '01'.
#5. Select munprod from Availability Groups tab **NOTE: There are 2 munprods, get the one on 01...NOT 02
munprods = WebDriverWait(browser, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//span[contains(text(), 'munprod')]")))
for munprod in munprods:
munprodServer = munprod.find_element(By.XPATH, '//following::td')
if munprodServer.find_element(By.XPATH, '//div[contains(text(), "01.jefferson.ketsds.net")]'):
munprod.click()
logger.info("Step 5: Databases --> munprod 01.jefferson.ketsds.net selected")
break
I know it's host '02' because when it hits the munprod.click() line it goes to the next screen and shows that it's for host '02'. Can a pair of fresh eyes spot what I'm doing wrong?
Solution
You have to use a 'period' (.) in front of your XPath expressions when looking for some element(s) under already located element.
This will ensure that your starting point is the element you are doing 'find_element' from.
So:
munprodServer = munprod.find_element(By.XPATH, '//following::td')
Should be:
munprodServer = munprod.find_element(By.XPATH, './/following::td')
And:
if munprodServer.find_element(By.XPATH, '//div[contains(text(), "01.jefferson.ketsds.net")]'):
Should be:
if munprodServer.find_element(By.XPATH, './/div[contains(text(), "01.jefferson.ketsds.net")]'):
Without the period, Selenium may search over the entire document, which could lead to some random and unexpected results.
Answered By - sashkins
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.