3

I am writing script using selenium python but there is problem i have tried to find solution but i can not find one that was helpful to me. here is the code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import unittest
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

class sulekhastart(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_parse_contact_urls_and_go_to_next_page(self):

        pagenumber = 'Page'

        #assign WEBDRIVER to local webdriver
        driver = self.driver

        #Website open by below url
        driver.get("http://www.sulekha.com/ac-dealers/bangalore")
        self.assertIn("Sulekha Bangalore", driver.title)

        #close the lightbox thnat appears at the firsttime load of page
        startlightbox = driver.find_element_by_xpath('//a[@class="lcf-close"]')
        startlightbox.click()

        while True:

            #get the page number
            pageno = driver.find_element_by_xpath('//li[@id="numberPage"]/strong')
            print pageno.text
            print pagenumber

            #check if page same as last page or not
            if str(pageno.text) != pagenumber:

                pagenumber = str(pageno.text)

                businessname = driver.find_elements_by_xpath('//li/div/div[@class="busi-name"]/h3/a')
                records = len(businessname)

                #print all data that are available on the webpage
                for i in range(0,records):
                    print businessname[i].get_attribute('href')
                    print businessname[i].text

                nextpage = driver.find_element_by_xpath('//li[@id="nextPage"]')
                nextpage.click()
            else:
                print 'This is last page all data is scraped change url and get another data'
                break

            element = WebDriverWait(driver, 10).until_not(EC.presence_of_element_located((By.XPATH, "/html/body/div/div/svg")))

    def tearDown(self):
        self.driver.close()
        print 'page not be closed'

if __name__ == "__main__":
    unittest.main()

and i want to wait script after click on the next button until By.XPATH, "/html/body/div/div/svg" this element gone from DOM or page source and then after wait until 3 seconds

3
  • 2
    Try "/html/body/div/div/*[name()='svg']" instead Commented May 28, 2017 at 11:08
  • 1
    Trust me and just try it :))) Commented May 28, 2017 at 11:14
  • 1
    hey thanks it is working @Andersson Commented May 28, 2017 at 11:23

1 Answer 1

2

as andersson commented

replacing

element = WebDriverWait(driver, 10).until_not(
            EC.presence_of_element_located((
              By.XPATH, "/html/body/div/div/svg")))

with

element = WebDriverWait(driver, 10).until_not(
            EC.presence_of_element_located((
              By.XPATH, "/html/body/div/div/*[name()='svg']")))

solves the problem

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

Comments

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.