2

I'm new to python and selenium. I want to click on the get_likes_button and I need to send the value = 1803345990687013485 when doing that.


Here's the HTML

<form action="" method="post" accept-charset="utf-8"><span style="font-size: 14px;"> 
<i class="fa fa-heart" style="color: #F12938;"></i> 20 </span> 
<input type="hidden" value="1803345990687013485" name="id">
<button class="btn btn-primary pull-right" type="submit" name="submit"
 id="get_likes_button"> Get Likes </button> </form></b>

Here's the code

driver.find_element_by_xpath("//input[@name='id']").send_key('1803345990687013485')
driver.find_element_by_id('get_likes_button').submit()

I get the following message

Exception: Message: Element not visible.

3
  • Where are you getting the exception? note that the first element has type='hidden' attribute. In addition, get_likes_button is id, not name. Commented Jun 17, 2018 at 7:46
  • Use findElementById() because get_likes_button is id. Commented Jun 17, 2018 at 7:47
  • I changed it to findElementById() but I'm still getting the same error message Commented Jun 17, 2018 at 8:36

3 Answers 3

1

This error message...

Exception: Message: Element not visible.

...implies that the desired element is not visible.

The main issue is the <input> tag is having an attribute type="hidden".

To send the character sequence 1803345990687013485 to the input field and invoke click() on the button you can use the following solution:

driver.execute_script("document.getElementsByName('id')[0].setAttribute('type','text')")
driver.find_element_by_xpath("//input[@name='id']").send_key('1803345990687013485')
driver.find_element_by_xpath("//button[@class='btn btn-primary pull-right' and @id='get_likes_button']").click()
Sign up to request clarification or add additional context in comments.

Comments

0

For clicking on Get Likes button you can use this code :

get_likes = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "get_likes_button")))  

After that if input type changed from type='hidden' , you can interact with input field as :

input_field = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.NAME, "id")))  

It's quite strange to see HTML like this :

<input name="id">  

By the way, hope this will help.

Comments

0

Try below snippet. Hope this will help you.

WebDriver driver = new FirefoxDriver();
driver.navigate().to(URL);                    
JavascriptExecutor javascriptExecuter = (JavascriptExecutor)driver;
javascriptExecuter.executeScript("document.getElementsByName('id')[0].value='452525252525';");
driver.findElement(By.id("get_likes_button")).submit();

1 Comment

The above code written in java. Use JavascriptExecutor for updating hidden field value like above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.