Reputation: 946
I have used below code using xpath selector. but it is not working. kindly guide me who knows this issue and where i made mistake in this code.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class CGBrowseJobs(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://www.ionface.com/"
self.verificationErrors = []
def test_c_g_browse_jobs(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_link_text("Career Grab").click()
driver.find_element_by_xpath("//a[text()='Browse Jobs']/@href").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
`
Upvotes: 0
Views: 3297
Reputation: 25056
You have included the @href attribute in your XPath, use this instead:
driver.find_element_by_xpath("//a[text()='Browse Jobs']").click()
Selenium does not need to be given a link directly (like using the @href attribute). Give it an entire element and let it pick out the URL for you.
Upvotes: 2