Reputation: 309
I'm trying to click the "next" button on the bottom of this page: https://www.domcop.com/domains/great-expired-domains/
I've tried with a css selector using .select, with xpath and with Selenium and nothing worked.
I think the button is generating a JQuery code to list the domains on the same page which would explain why python can't click it with xpath and .select.
However, I couldn't figure out how to click it with Selenium...
Here's my script:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.domcop.com/domains/great-expired-domains/")
assert "Python" in driver.title
link = driver.find_element_by_class_name('next').get_attribute('a')
It returns a 'NoneType' object...
Any help would be much appreciated!
Thank you
Upvotes: 1
Views: 1313
Reputation: 432
find_element(:xpath, '//*[@id="domcop-table_wrapper"]/div[position()>1]/div[position()>1]/div/ul/li[6]/a/i[@class="icon-double-angle-right"]')
This Xpath will ALWAYS work. You can scroll down afterwards and click
I just did not scroll down. thats all.
Check this Xpath
(:xpath, '//*[@id="domcop-table_wrapper"]/div[not(contains(text(),
"Display")) and not(contains(text(),"records"))]/descendant::li[@class="next"]/a/i[@class="icon-double-angle-right"]')
Upvotes: 0
Reputation: 5137
See code below:
driver.get('https://www.domcop.com/domains/great-expired-domains/')
aElements = driver.find_elements_by_css_selector('.next > a')
driver.execute_script('window.scrollTo(0, document.body.scrollHeight);')
aElements[1].click()
Upvotes: 2
Reputation: 89315
Unlike common XML/HTML parser, selenium simulates browser behaviour, so it shouldn't have problem with elements generated by JQuery as you seem concrerned about. The problem with your selector was, that a
is not attribute of element with class next
, it is child of next
instead. Therefore you can use CSS selector for child >
here :
link = driver.find_element_by_css_selector('.next > a')
link.click()
Upvotes: 3