Python Selenium Css Selector: Element Is Not Visible
I want to locate all the hyperlinks in a webpage which has a xml download link and download them in a loop. There is form which arises when the said hyperlink is clicked, and need
Solution 1:
You have to locate only the XML not all hyper links. your locator //*[@href]
is locating all the HREF links. Use below code
#locate all the links which have xml
allelements = driver.find_elements_by_xpath("//a[text()='xml']")
# Iterate all links one by one
for element in allelements:
element.click()
class FormPage(object):
def fill_form(self, data):
driver.execute_script("document.getElementById('edit-download-reasons-non-commercial').click()")
driver.execute_script("document.getElementById('edit-reasons-d-rd').click()")
driver.find_element_by_xpath('//input[@name = "name_d"]').send_keys(data['name_d'])
driver.find_element_by_xpath('//input[@name = "mail_d"]').send_keys(data['mail_d'])
return self
def submit(self):
driver.execute_script("document.getElementById('edit-submit').click()")
data = {
'name_d': 'xyz',
'mail_d': 'xyz@outlook.com',
}
time.sleep(5)
FormPage().fill_form(data).submit()
#It opens the download link in new tab So below code again switch back to parent window itself
window_before = driver.window_handles[0]
driver.switch_to_window(window_before)
Post a Comment for "Python Selenium Css Selector: Element Is Not Visible"