English 中文(简体)
Python Selenium Webdriver: Cannot locate confirmation dialog (reveal-overlay class object) after submit button
原标题:

I m using Selenium Webdriver and python to automatically schedule an appointment.

Webdriver options:

options = Options()
options.binary_location =  /opt/headless-chromium 
options.add_argument( --headless )
options.add_argument( --no-sandbox )
options.add_argument( --single-process )
options.add_argument( --disable-dev-shm-usage )

driver = webdriver.Chrome( /opt/chromedriver ,chrome_options=options)
driver.maximize_window()

I was able to select the date I want for the appointment and to find the submit button.

The html of the submit button (you can see the dialog configured at the data-confirm attribute):

<input type="submit" name="commit" value="Reprogramar" id="appointments_submit" data-confirm="{&quot;title&quot;:&quot;¿Desea reprogramar esta cita?&quot;,&quot;ok&quot;:&quot;Confirmar&quot;,&quot;cancel&quot;:&quot;Cancelar&quot;}" data-disable-with="Por favor, espere." class="button primary">

How I m finding it:

appointments_submit = driver.find_element(By.ID,  appointments_submit )
appointments_submit.click()

However, when I click the submit button, it creates a confirmation dialog (which doesn t appear in the body of the page until this moment). Not matter how much I try, I cannot made the web driver able to locate this element.

Html of the element:

<div class="reveal-overlay" style="display: block;"><div data-reveal="ib04bi-reveal" class="reveal " role="dialog" aria-hidden="false" tabindex="-1" style="display: block; top: 97px;">
  <h2 data-confirm-title="" class="h3 text-center alert-icon">¿Desea reprogramar esta cita?</h2>
  <p data-confirm-body="" class=""></p>
  <div data-confirm-footer="" class="text-center">
    <a data-confirm-cancel="" class="button secondary">Cancelar</a>
  <a class="button alert">Confirmar</a></div>
<a aria-label="Close modal" class="close-button" data-close="">
  <span aria-hidden="true" class="fas fa-times"></span>
  </a>
  </div></div>

Picture of it: element webdriver cannot locate

This is where is failing:

confirmation_button = driver.find_element(By.CSS_SELECTOR,  body > div.reveal-overlay > div > div > a.button.alert )

confirmation_button .click()
[ERROR] NoSuchElementException: Message: no such element: Unable to locate element: 
{
    "method": "css selector",
    "selector": "body > div.reveal-overlay > div > div > a.button.alert"
}

I also tried WebDriverWait but is not working neither as is throwing a TimeOutException:

This didn t work neither.

confirmation_button = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CSS_SELECTOR, "body > div.reveal-overlay > div > div > a.button.alert")))
confirmation_button .click()

Please help me troubleshoot this issue. I m feeling really stuck with it.

PD: I m running the code in a python3.7 aws lambda function

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签