1

I am going through the table at the following link:

http://cancer.sanger.ac.uk/cosmic/sample/overview?id=2120881

through selenium in python. This is the code:

driver = webdriver.Chrome()
driver.get('http://cancer.sanger.ac.uk/cosmic/sample/overview?id=2120881')
elem = driver.find_element_by_link_text("Variants")

while elem:
    elem.click()
    time.sleep(5)
    try:
        elem = driver.find_element_by_link_text("Next")
        print(elem.is_enabled())
        if 'disabled' in elem.get_attribute('class'):
            break
    except:
        print('Next not available or page not loaded!')
driver.quit()

I have trouble changing the number of displayed values to 100. How would I do that?

Also, why does the is_enabled() return True even when the button becomes unclickable?

Thanks in advance!

4
  • as far as to you is_enabled() being true, that just says it finds it so yeah.... it could you try.... "driver.find_element_by_link_text("Variants").click()" If that works the I assume the first elem isnt being clicked by just ... "elem.click() in you while statement" Commented Jun 29, 2017 at 20:00
  • how about using the .sendKeys(Keys.Enter); see what goes with that Commented Jun 29, 2017 at 20:01
  • Thanks! Can you elaborate on that idea with the sendKeys()? Commented Jun 29, 2017 at 20:43
  • 1
    Sorry to be short my friend! If your still havingissuesin thenext 6 hours Ill through up aproper answer but okay...so you say the element is no clicking.... how about if instead of click you jus get the driver to select the element and press enter..... might beworth tryingout realquick Commented Jun 29, 2017 at 23:29

1 Answer 1

3

Q: I have trouble changing the number of displayed values to 100. How would I do that? Solution: You have to use Select Class (link) to select value from Dropdown

Question:why does the is_enabled() return True even when the button becomes unclickable?

The is_enabled() is returning True only when it is as you can see the True is only printed three times when it was enabled and post that its enter in break loop and exits as expected

Just updated your code with Select and break print statement:

from selenium import webdriver
import time
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('http://cancer.sanger.ac.uk/cosmic/sample/overview?id=2120881')
elem = driver.find_element_by_link_text("Variants")



while elem:
    elem.click()
    time.sleep(5)
    select = Select(driver.find_element_by_name('DataTables_Table_0_length'))
    select.select_by_value('100') # you can use any value 
    try:
        elem = driver.find_element_by_link_text("Next")
        print(elem.is_enabled())
        if 'disabled' in elem.get_attribute('class'):
            print "Before Break"
            break
    except:
        print('Next not available or page not loaded!')

driver.quit()

The output is:

True
True
True
Before Break
Sign up to request clarification or add additional context in comments.

2 Comments

Not sure I follow about the second one. If you remove the break statement, it will go in a loop printing true, even though the element is disabled. The only reason it quits here is because the class name is changed to contain the word disabled!
@CindyAlmighty the isenabled() is working as expected: see the reference link github.com/angular/protractor/issues/577 and stackoverflow.com/questions/31078873/…

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.