0

I'm trying to make a bot that creates accounts for me, but I can't interact with the element where I need to send my credentials.

All I know is that the element that I'm trying to interact with is generated in javascript, after clicking on another button. I found multiple answers but all were in others languages than Node.js.

I'm trying to send credentials on this element:

<input type="text" name="pseudo" id="pseudo" placeholder="Mon pseudo légendaire" style="margin-bottom: 10px;" maxlength="10">

I tried to use this:

driver.findElement(By.xpath('//*[@id="pseudo"]')).sendKeys('CREDITENTIALS')

Which returns me this error: Webdrivererror: element is not visible.

HTML element code looks like this :

<input type="text" name="pseudo" id="pseudo" placeholder="Mon pseudo légendaire" style="margin-bottom: 10px;" maxlength="10">

The problem is not that i have to wait until the element that im trying to interact with is displayed because it is already displayed, the problem is that i want to click on the second element that match with my findElement by xpath, because what im trying to click on is existing 2 times in the html code and only the second one is interactible.


Update (from the comments)

This element is within the following <div> tag:

<div id="modal_message_wrapper" class="block_scrollable_wrapper scrollbar-light yellow noise inscription">
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Zayonx
  • 164
  • 1
  • 12
  • Do you have a `waitForElementVisible` command? – Lee Kowalkowski Jul 09 '18 at 12:51
  • No, i don't have a `waitForElementVisible` command. – Zayonx Jul 09 '18 at 12:55
  • If you have other examples of selenium scripts they should just work. Selenium is language agnostic, the syntax might change slightly, uppercase lowercase letters on interfaces, etc. but the underlying principle should work – Liam Jul 09 '18 at 14:21
  • It sounds like your actual problem is this [How to force Selenium WebDriver to click on element which is not currently visible?](https://stackoverflow.com/questions/6101461/how-to-force-selenium-webdriver-to-click-on-element-which-is-not-currently-visib) – Liam Jul 09 '18 at 14:22
  • That all said we need a [Minimal, Complete, and Verifiable example](http://idownvotedbecau.se/nomcve/) of your problem or else we're just guessing – Liam Jul 09 '18 at 14:25
  • Possible duplicate of [Selenium WebDriver wait till element is displayed](https://stackoverflow.com/questions/25753014/selenium-webdriver-wait-till-element-is-displayed) – JeffC Jul 09 '18 at 14:29
  • But the element is displayed, waiting for years won't solve my problem.. – Zayonx Jul 09 '18 at 14:30
  • The problem is that there is the same element that im trying to click 2 times and the first one isn't displayed, so i want to click the second one.. – Zayonx Jul 09 '18 at 14:32

1 Answers1

1

You can construct an unique xpath clubbing up the id, name and placeholder attribute as follows:

driver.findElement(By.xpath("//input[@id='pseudo' and @name='pseudo' and @placeholder='Mon pseudo légendaire']")).sendKeys('CREDITENTIALS')

Update

As you mentioned that the desired element is within:

<div id="modal_message_wrapper" class="block_scrollable_wrapper scrollbar-light yellow noise inscription">

So you can use the following line of code:

driver.findElement(By.xpath("//div[@class='block_scrollable_wrapper scrollbar-light yellow noise inscription' and @id='modal_message_wrapper']//input[@id='pseudo' and @name='pseudo' and @placeholder='Mon pseudo légendaire']")).sendKeys('CREDITENTIALS')

Note: It's quite evident the element is within a Modal Dialog Box, so definitely you have to induce a waiter in the form of WebDriverWait before you attempt to send any character sequence to the <input> element.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352