0

I'm using send_keys to populate a text field in selenium. However, it takes a few seconds for the text to appear.

I would like this faster.

This is currently my xpath along with the sen_keys.

post_box = WebDriverWait(driver, 20).until(
                        EC.element_to_be_clickable((By.XPATH, "/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div/div[1]/form/div/div[1]/div/div/div[1]/div/div[2]/div[1]/div[1]/div[1]/div/div/div/div/div[2]/div/div/div/div"))).send_keys(self.textContents)

And this is the html where i use it

<div data-offset-key="a467s-0-0" class="_1mf _1mj"><span data-offset-key="a467s-0-0"><br data-text="true"></span></div>

Thanks in advance.

xalom
  • 41
  • 5

1 Answers1

0

For Selenium to traverse through the long absolute xpath based path may be taking some more computing time.

A simple solution would be to use relative xpath as follows:

//div[@attributeA='attributeA_value' and @attributeB='attributeB_value'][@attribute='attributeC_value']

An Example

As an example for a <div> like:

<div class="entry" id="element_id" value="element_value"></div>

Your effective xpath would be:

//div[@class='entry' and @id='element_id'][@value='element_value']

Updating your code block will look like:

post_box = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='entry' and @id='element_id'][@value='element_value']"))).send_keys(self.textContents)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • How can i convert my xpath to a relative xpath based on your answer? – xalom Apr 05 '22 at 17:06
  • this is the html where i use it

    – xalom Apr 05 '22 at 17:09
  • @xalom I saw your questionn edit. You are editing a `
    `, so for a effective xpath as per the HTML you need to show us the HTML including the `
    ` which contains the attribute [contenteditable="true"](https://stackoverflow.com/a/70822222/7429447)
    – undetected Selenium Apr 05 '22 at 17:17