Answer the question
In order to leave comments, you need to log in
selenium. Working with tabs in Python?
Good people, don't judge cruelly, I'm just learning, despair has come and I really hope for your help, I can't learn how to switch between windows on selemiun (python).
Here is my code, the task is simple in two pages to log in to social networks:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
class Bot:
def __init__(self):
self.driver = webdriver.Firefox()
self.authorization_vk()
self.authorization_fb()
def authorization_vk(self): #АВТОРИЗАЦИЯ VK:
self.driver.get('https://vk.com')
self.driver.find_element_by_xpath('//*[@id="index_email"]').send_keys("email")
self.driver.find_element_by_xpath('//*[@id="index_pass"]').send_keys("pass")
self.driver.find_element_by_xpath('//*[@id="index_login_button"]').click()
def authorization_fb(self): #АВТОРИЗАЦИЯ fb:
self.driver.execute_script("window.open('https://www.facebook.com','_blank');") # Интуитивно вставила так ссылку и она хотя бы заработала, возможно есть другие варианты...
self.driver.switch_to_window(driver.window_handles[1]) #Пробовала вычислять окна и вставлять номер id конкретного окна, что-то мелькало на экране, но результата не дало.
self.driver.find_element_by_xpath('//*[@id="email"]').send_keys("email")
self.driver.find_element_by_xpath('//*[@id="pass"]').send_keys("pass")
self.driver.find_element_by_xpath('//*[@id="u_0_2"]').click()
def main():
b = Bot()
if __name__ == '__main__':
main()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question