Home > Enterprise >  Selenium didnt reach the modal like element
Selenium didnt reach the modal like element

Time:09-29

when I click job info, a panel opens with information but I can not get the element with xpath or any other selectors I get:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[15]"} (Session info: chrome=105.0.5195.127)

My Code to click job info and to get element modal:

job_info =wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="tab-1300-btnInnerEl"]'))) 
ActionChains(driver).move_to_element(job_info).click().perform()
            
job_info2 = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/div[3]/div[2]/div[2]/div/div/a[2]/span/span/span[2]')))
ActionChains(driver).move_to_element(job_info2).click().perform()
            
accept_btn = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/div[13]/div[3]/div/div/div[2]/div/div/div/div[6]/div/div/div/div[2]/div[2]/div/div[2]/div/div[1]/table[1]/tbody/tr/td[5]')))
ActionChains(driver).move_to_element(job_info2).click().perform()
sleep(2)
modal = driver.find_element(By.XPATH,'/html/body/div[15]')
print(modal.get_attribute('innerHTML'))

enter image description hereenter image description here

from fileinput import close
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep

# login informations
user = [
        'user_email',
        'user_password'
        ]

# url to login
url =  'https://dashboard.transperfect.com/'


# install chrome driver and start chrome
driver = webdriver.Chrome(ChromeDriverManager().install())
wait = WebDriverWait(driver,15)
driver.get(url)

# Accept cookie options on opening
cookie_accept = wait.until(EC.presence_of_element_located((By.NAME,'accept-seleted'))) 
cookie_accept.click()


# login attempt
email = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/main/div[1]/section/form/div[1]/input'))).send_keys(user[0])
continue_btn = wait.until(EC.presence_of_element_located((By.ID,'SubmitLogin')))
continue_btn.click()
password = wait.until(EC.presence_of_element_located((By.ID,'Password'))).send_keys(user[1])
continue_btn2 = wait.until(EC.presence_of_element_located((By.ID,'SubmitLogin')))
continue_btn2.click()

driver.get('https://gl-tptprod1.transperfect.com/PD/SSO')
driver.set_window_size(1000,500)
while True:
    # click inbox
    inbox = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/div[2]/div/div/div[2]/div/div/div/div/div/a[2]/span')))
    sleep(1)
    ActionChains(driver).move_to_element(inbox).click().perform()
    print('click to inbox')
    try:
        jobs = wait.until(EC.presence_of_all_elements_located((By.TAG_NAME,'table')))
    except:
        print('inbox da iş yok')
    else:
        for job in jobs:
            ActionChains(driver).move_to_element(job).click().perform()
            
            job_info =wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="tab-1300-btnInnerEl"]'))) 
            ActionChains(driver).move_to_element(job_info).click().perform()
            
            job_info2 = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/div[3]/div[2]/div[2]/div/div/a[2]/span/span/span[2]')))
            ActionChains(driver).move_to_element(job_info2).click().perform()
            
            accept_btn = wait.until(EC.presence_of_element_located((By.XPATH,'/html/body/div[13]/div[3]/div/div/div[2]/div/div/div/div[6]/div/div/div/div[2]/div[2]/div/div[2]/div/div[1]/table[1]/tbody/tr/td[5]')))
            ActionChains(driver).move_to_element(job_info2).click().perform()
            sleep(2)
            modal = driver.find_element(By.XPATH,'/html/body/div[15]')
            print(modal.get_attribute('innerHTML'))

CodePudding user response:

Try with following xpath to identify the element

//div[contains(@id, 'pdSubmissionBudgetJobInfoDialog-')]

code:

modal = driver.find_element(By.XPATH,"//div[contains(@id,'pdSubmissionBudgetJobInfoDialog-')]")
print(modal.get_attribute('innerHTML'))

To avoid sync issue use visibility_of_element_located()

modal=wait.until(EC.visibility_of_element_located((By.XPATH,"//div[contains(@id,'pdSubmissionBudgetJobInfoDialog-')]")))
print(modal.get_attribute('innerHTML')) 
  • Related