简体   繁体   中英

How to access newly opened small tab in the current tab using selenium web driver python

I clicked on sign in button from the below link and it is opened a small tab inside the same window. i want to access the current small tab and fill information. url: https://www.tajawal.ae/en Kindly suggest how i can do this using python selenium webdriver

I checked the URL which you shared, the small tab/web popup neither appears in new frame nor in new window, so you don't need to do frame/window switch. you can simply access popup elements

In-case, if you had tried to interact with 'email' input box in the small pop up and if it has not worked, please see my answer below.

You have 2 email inputs boxes with the same name(attribute name) - "email", one in popup, another one in the same page under subscribe to newsletter section. If you had tried to enter something in popup's email input box, it would have entered in the newsletter section. So to enter correctly in popup's email input box, use xpath --> (//input[@name='email'])[2]

To send a character sequence to the Email and Password field within the website https://www.tajawal.com/en you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies :

  • Using XPATH :

     driver.get("https://www.tajawal.com/en") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-testid='Header__SignInButton']"))).click() WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[text()='Email']//following::input[@name='email']"))).send_keys("paul@paul.paul") driver.find_element_by_xpath("//label[text()='Password']//following::input[@name='password']").send_keys("paul@paul.paul")
  • Note : You have to add the following imports:

     from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
  • Browser Snapshot:

塔贾瓦尔

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM